toolbar.c 104 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3
/*
 * Toolbar control
 *
4
 * Copyright 1998,1999 Eric Kohl
Alexandre Julliard's avatar
Alexandre Julliard committed
5 6
 *
 * TODO:
7 8
 *   - A little bug in TOOLBAR_DrawMasked()
 *   - Button wrapping (under construction).
Alexandre Julliard's avatar
Alexandre Julliard committed
9
 *   - Messages.
10
 *   - Notifications (under construction).
11
 *   - Fix TB_SETROWS.
Alexandre Julliard's avatar
Alexandre Julliard committed
12
 *   - Tooltip support (almost complete).
13 14
 *   - Unicode suppport (under construction).
 *   - Fix TOOLBAR_SetButtonInfo32A/W.
15
 *   - Customize dialog (under construction).
16 17
 *   - TBSTYLE_AUTOSIZE for toolbar and buttons.
 *   - I_IMAGECALLBACK support.
Alexandre Julliard's avatar
Alexandre Julliard committed
18 19 20 21 22 23 24 25
 *
 * Testing:
 *   - Run tests using Waite Group Windows95 API Bible Volume 2.
 *     The second cdrom contains executables addstr.exe, btncount.exe,
 *     btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
 *     enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
 *     indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
 *     setparnt.exe, setrows.exe, toolwnd.exe.
Alexandre Julliard's avatar
Alexandre Julliard committed
26
 *   - Microsofts controlspy examples.
Alexandre Julliard's avatar
Alexandre Julliard committed
27 28
 */

29 30
#include <string.h>

31
#include "winbase.h"
32 33
#include "windef.h"
#include "wingdi.h"
34
#include "winuser.h"
35
#include "wine/unicode.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
36
#include "commctrl.h"
37
#include "imagelist.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
38
#include "cache.h"
39
#include "comctl32.h"
40
#include "debugtools.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
41

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
DEFAULT_DEBUG_CHANNEL(toolbar);

typedef struct
{
    INT iBitmap;
    INT idCommand;
    BYTE  fsState;
    BYTE  fsStyle;
    DWORD dwData;
    INT iString;

    BOOL bHot;
    INT nRow;
    RECT rect;
} TBUTTON_INFO; 

typedef struct
{
    DWORD      dwStructSize;   /* size of TBBUTTON struct */
    INT      nHeight;        /* height of the toolbar */
    INT      nWidth;         /* width of the toolbar */
    INT      nButtonHeight;
    INT      nButtonWidth;
    INT      nBitmapHeight;
    INT      nBitmapWidth;
    INT      nIndent;
    INT      nRows;           /* number of button rows */
    INT      nMaxTextRows;    /* maximum number of text rows */
    INT      cxMin;           /* minimum button width */
    INT      cxMax;           /* maximum button width */
    INT      nNumButtons;     /* number of buttons */
    INT      nNumBitmaps;     /* number of bitmaps */
    INT      nNumStrings;     /* number of strings */
    BOOL     bUnicode;        /* ASCII (FALSE) or Unicode (TRUE)? */
    BOOL     bCaptured;       /* mouse captured? */
    INT      nButtonDown;
    INT      nOldHit;
    INT      nHotItem;        /* index of the "hot" item */
    HFONT    hFont;           /* text font */
    HIMAGELIST himlInt;         /* image list created internally */
    HIMAGELIST himlDef;         /* default image list */
    HIMAGELIST himlHot;         /* hot image list */
    HIMAGELIST himlDis;         /* disabled image list */
    HWND     hwndToolTip;     /* handle to tool tip control */
    HWND     hwndNotify;      /* handle to the window that gets notifications */
    BOOL     bTransparent;    /* background transparency flag */
    BOOL     bAutoSize;       /* auto size deadlock indicator */
    BOOL     bAnchor;         /* anchor highlight enabled */
    DWORD      dwExStyle;       /* extended toolbar style */
    DWORD      dwDTFlags;       /* DrawText flags */

    COLORREF   clrInsertMark;   /* insert mark color */
    RECT     rcBound;         /* bounding rectangle */
    INT      iVersion;

    TBUTTON_INFO *buttons;      /* pointer to button array */
    LPWSTR       *strings;      /* pointer to string array */
} TOOLBAR_INFO;
100

Alexandre Julliard's avatar
Alexandre Julliard committed
101 102 103
#define SEPARATOR_WIDTH    8
#define TOP_BORDER         2
#define BOTTOM_BORDER      2
Alexandre Julliard's avatar
Alexandre Julliard committed
104

105
#define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
Alexandre Julliard's avatar
Alexandre Julliard committed
106

107 108 109 110 111 112 113 114 115
static BOOL 
TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
{
    if ((index>=0) && (index < infoPtr->nNumBitmaps))
      return TRUE;
    else
      return FALSE;
}

116

Alexandre Julliard's avatar
Alexandre Julliard committed
117
static void
118
TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
119
{
120 121 122
    INT x = (lpRect->left + lpRect->right) / 2 - 1;
    INT yBottom = lpRect->bottom - 3;
    INT yTop = lpRect->top + 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
123

124 125 126
    SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
    MoveToEx (hdc, x, yBottom, NULL);
    LineTo (hdc, x, yTop);
Alexandre Julliard's avatar
Alexandre Julliard committed
127
    x++;
128 129 130
    SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
    MoveToEx (hdc, x, yBottom, NULL);
    LineTo (hdc, x, yTop);
Alexandre Julliard's avatar
Alexandre Julliard committed
131 132
}

133 134
/*
 * Draw the text string for this button.
135 136 137
 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
 * 	is non-zero, so we can simply check himlDef to see if we have
 *      an image list
138
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
139 140
static void
TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
141
		    HDC hdc, INT nState, DWORD dwStyle)
Alexandre Julliard's avatar
Alexandre Julliard committed
142
{
143 144 145
    RECT   rcText = btnPtr->rect;
    HFONT  hOldFont;
    INT    nOldBkMode;
Alexandre Julliard's avatar
Alexandre Julliard committed
146
    COLORREF clrOld;
147
    LPWSTR lpText = NULL;
148
    HIMAGELIST himl = infoPtr->himlDef;
149

150
    TRACE ("iString: %x\n", btnPtr->iString);
151 152

    /* get a pointer to the text */
153 154 155 156
    if (btnPtr->iString == -1)
        FIXME("Undocumented Index -1\n");
    else if (HIWORD(btnPtr->iString) != 0)
        lpText = (LPWSTR)btnPtr->iString;
157
    else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
158
        lpText = infoPtr->strings[btnPtr->iString];
159 160

    TRACE ("lpText: \"%s\"\n", debugstr_w(lpText));
Alexandre Julliard's avatar
Alexandre Julliard committed
161 162

    /* draw text */
163
    if (lpText) {
164

165
	InflateRect (&rcText, -3, -3);
166

167
	if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
168 169 170
		if ((dwStyle & TBSTYLE_LIST) &&
		    ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
		    (btnPtr->iBitmap != I_IMAGENONE)) {
171 172 173 174 175
		    rcText.left += infoPtr->nBitmapWidth;
		}
		else {
		    rcText.top += infoPtr->nBitmapHeight;
		}
176
	}
177

Alexandre Julliard's avatar
Alexandre Julliard committed
178
	if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
179
	    OffsetRect (&rcText, 1, 1);
Alexandre Julliard's avatar
Alexandre Julliard committed
180

181 182
	hOldFont = SelectObject (hdc, infoPtr->hFont);
	nOldBkMode = SetBkMode (hdc, TRANSPARENT);
Alexandre Julliard's avatar
Alexandre Julliard committed
183
	if (!(nState & TBSTATE_ENABLED)) {
184 185
	    clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
	    OffsetRect (&rcText, 1, 1);
186
	    DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
187 188
	    SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
	    OffsetRect (&rcText, -1, -1);
189
	    DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
Alexandre Julliard's avatar
Alexandre Julliard committed
190 191
	}
	else if (nState & TBSTATE_INDETERMINATE) {
192
	    clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
193
	    DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
Alexandre Julliard's avatar
Alexandre Julliard committed
194 195
	}
	else {
196
	    clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
197
	    DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
Alexandre Julliard's avatar
Alexandre Julliard committed
198 199
	}

200 201
	SetTextColor (hdc, clrOld);
	SelectObject (hdc, hOldFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
202
	if (nOldBkMode != TRANSPARENT)
203
	    SetBkMode (hdc, nOldBkMode);
Alexandre Julliard's avatar
Alexandre Julliard committed
204 205 206 207
    }
}


Alexandre Julliard's avatar
Alexandre Julliard committed
208
static void
209
TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
Alexandre Julliard's avatar
Alexandre Julliard committed
210
{
211 212 213 214 215
    HBRUSH hbr = SelectObject (hdc, CACHE_GetPattern55AABrush ());
    INT cx = lpRect->right - lpRect->left;
    INT cy = lpRect->bottom - lpRect->top;
    PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
    SelectObject (hdc, hbr);
Alexandre Julliard's avatar
Alexandre Julliard committed
216 217 218 219 220
}


static void
TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
221
		    HDC hdc, INT x, INT y)
Alexandre Julliard's avatar
Alexandre Julliard committed
222 223 224 225
{
    /* FIXME: this function is a hack since it uses image list
	      internals directly */

226
    HIMAGELIST himl = infoPtr->himlDef;
227
    HBITMAP hbmMask;
228 229 230 231 232 233 234 235 236
    HDC hdcImageList;
    HDC hdcMask;

    if (!himl)
	return;

    /* create new dc's */
    hdcImageList = CreateCompatibleDC (0);
    hdcMask = CreateCompatibleDC (0);
Alexandre Julliard's avatar
Alexandre Julliard committed
237

238
    /* create new bitmap */
239 240
    hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
    SelectObject (hdcMask, hbmMask);
241 242

    /* copy the mask bitmap */
243 244 245 246
    SelectObject (hdcImageList, himl->hbmMask);
    SetBkColor (hdcImageList, RGB(255, 255, 255));
    SetTextColor (hdcImageList, RGB(0, 0, 0));
    BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
247 248 249 250
	      hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);

#if 0
    /* add white mask from image */
251 252 253
    SelectObject (hdcImageList, himl->hbmImage);
    SetBkColor (hdcImageList, RGB(0, 0, 0));
    BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
254 255
	      hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
#endif
Alexandre Julliard's avatar
Alexandre Julliard committed
256

257
    /* draw the new mask */
258 259
    SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
    BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
260
	      hdcMask, 0, 0, 0xB8074A);
Alexandre Julliard's avatar
Alexandre Julliard committed
261

262 263
    SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
    BitBlt (hdc, x, y, himl->cx, himl->cy,
264
	      hdcMask, 0, 0, 0xB8074A);
Alexandre Julliard's avatar
Alexandre Julliard committed
265

266 267 268
    DeleteObject (hbmMask);
    DeleteDC (hdcMask);
    DeleteDC (hdcImageList);
Alexandre Julliard's avatar
Alexandre Julliard committed
269 270 271
}


Alexandre Julliard's avatar
Alexandre Julliard committed
272
static void
273
TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
274
{
275 276
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
277
    RECT rc;
Alexandre Julliard's avatar
Alexandre Julliard committed
278

279 280
    if (btnPtr->fsState & TBSTATE_HIDDEN)
	return;
Alexandre Julliard's avatar
Alexandre Julliard committed
281 282

    rc = btnPtr->rect;
283

284 285
    TRACE("iBitmap: %d\n", btnPtr->iBitmap);

286
    /* separator */
Alexandre Julliard's avatar
Alexandre Julliard committed
287
    if (btnPtr->fsStyle & TBSTYLE_SEP) {
288 289 290 291 292 293
        /* with the FLAT style, iBitmap is the width and has already */
        /* been taken into consideration in calculating the width    */
        /* so now we need to draw the vertical separator             */
        /* empirical tests show that iBitmap can/will be non-zero    */
        /* when drawing the vertical bar...      */
        if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */)
294
	    TOOLBAR_DrawFlatSeparator (&rc, hdc);
Alexandre Julliard's avatar
Alexandre Julliard committed
295 296
	return;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
297

Alexandre Julliard's avatar
Alexandre Julliard committed
298 299
    /* disabled */
    if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
300 301 302 303
	if (!(dwStyle & TBSTYLE_FLAT))
	    DrawEdge (hdc, &rc, EDGE_RAISED,
		      BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
	
304 305
	if (infoPtr->himlDis && 
            TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
306
	    ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
307 308 309
				rc.left+1, rc.top+1, ILD_NORMAL);
	else
	    TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
Alexandre Julliard's avatar
Alexandre Julliard committed
310

311
	TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
Alexandre Julliard's avatar
Alexandre Julliard committed
312
	return;
Alexandre Julliard's avatar
Alexandre Julliard committed
313 314
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
315 316
    /* pressed TBSTYLE_BUTTON */
    if (btnPtr->fsState & TBSTATE_PRESSED) {
317 318 319
	if (dwStyle & TBSTYLE_FLAT)
	    DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE | BF_ADJUST);
	else
320
	    DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
321
        if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
322
	    ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
Alexandre Julliard's avatar
Alexandre Julliard committed
323
			rc.left+2, rc.top+2, ILD_NORMAL);
324
	TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
Alexandre Julliard's avatar
Alexandre Julliard committed
325 326
	return;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
327

328
    /* checked TBSTYLE_CHECK */
Alexandre Julliard's avatar
Alexandre Julliard committed
329 330
    if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
	(btnPtr->fsState & TBSTATE_CHECKED)) {
331
	if (dwStyle & TBSTYLE_FLAT)
332
	    DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
Alexandre Julliard's avatar
Alexandre Julliard committed
333 334
			BF_RECT | BF_MIDDLE | BF_ADJUST);
	else
335
	    DrawEdge (hdc, &rc, EDGE_SUNKEN,
Alexandre Julliard's avatar
Alexandre Julliard committed
336
			BF_RECT | BF_MIDDLE | BF_ADJUST);
Alexandre Julliard's avatar
Alexandre Julliard committed
337

Alexandre Julliard's avatar
Alexandre Julliard committed
338
	TOOLBAR_DrawPattern (hdc, &rc);
339
        
340
        if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
341
	    ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
342 343
			rc.left+2, rc.top+2, ILD_NORMAL);

344
	TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
Alexandre Julliard's avatar
Alexandre Julliard committed
345 346
	return;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
347

Alexandre Julliard's avatar
Alexandre Julliard committed
348 349
    /* indeterminate */	
    if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
350
	DrawEdge (hdc, &rc, EDGE_RAISED,
Alexandre Julliard's avatar
Alexandre Julliard committed
351
		    BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
Alexandre Julliard's avatar
Alexandre Julliard committed
352

Alexandre Julliard's avatar
Alexandre Julliard committed
353 354
	TOOLBAR_DrawPattern (hdc, &rc);
	TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
355
	TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
Alexandre Julliard's avatar
Alexandre Julliard committed
356
	return;
Alexandre Julliard's avatar
Alexandre Julliard committed
357
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
358

359
    /* normal state */
360 361
    if (dwStyle & TBSTYLE_FLAT)
    {
362
	if (btnPtr->bHot)
363
	    DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
364 365
	if (btnPtr->bHot && infoPtr->himlHot && 
            TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
366
	    ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
367
			    rc.left +2, rc.top +2, ILD_NORMAL);
368
	else if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
369
	    ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
370 371
			    rc.left +2, rc.top +2, ILD_NORMAL);
    }
372 373 374
    else
    {
	DrawEdge (hdc, &rc, EDGE_RAISED,
Alexandre Julliard's avatar
Alexandre Julliard committed
375
		BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
376

377
        if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
378
	    ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
379
			rc.left+1, rc.top+1, ILD_NORMAL);
380
    }
381

382
    TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
Alexandre Julliard's avatar
Alexandre Julliard committed
383 384 385 386
}


static void
387
TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
Alexandre Julliard's avatar
Alexandre Julliard committed
388
{
389
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
390
    TBUTTON_INFO *btnPtr;
391
    INT i;
392
    RECT rcTemp;
Alexandre Julliard's avatar
Alexandre Julliard committed
393

394
    /* redraw necessary buttons */
Alexandre Julliard's avatar
Alexandre Julliard committed
395
    btnPtr = infoPtr->buttons;
Alexandre Julliard's avatar
Alexandre Julliard committed
396
    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
397 398 399 400
    {
        if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
            TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
401 402
}

Alexandre Julliard's avatar
Alexandre Julliard committed
403
static void
404
TOOLBAR_MeasureString(HWND hwnd, INT index, LPSIZE lpSize)
Alexandre Julliard's avatar
Alexandre Julliard committed
405
{
406
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
407
    TBUTTON_INFO *btnPtr;
408 409
    HDC hdc;
    HFONT hOldFont;
410

Alexandre Julliard's avatar
Alexandre Julliard committed
411 412
    lpSize->cx = 0;
    lpSize->cy = 0;
413 414
    hdc = GetDC (0);
    hOldFont = SelectObject (hdc, infoPtr->hFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
415

416 417 418 419 420 421 422 423
    btnPtr = &infoPtr->buttons[index];

    if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
         (btnPtr->iString > -1) &&
         (btnPtr->iString < infoPtr->nNumStrings)) 
    {
        LPWSTR lpText = infoPtr->strings[btnPtr->iString];
        GetTextExtentPoint32W (hdc, lpText, lstrlenW (lpText), lpSize);
Alexandre Julliard's avatar
Alexandre Julliard committed
424 425
    }

426 427
    SelectObject (hdc, hOldFont);
    ReleaseDC (0, hdc);
Alexandre Julliard's avatar
Alexandre Julliard committed
428

429
    TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
Alexandre Julliard's avatar
Alexandre Julliard committed
430 431
}

432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
static void
TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    TBUTTON_INFO *btnPtr;
    INT i;
    SIZE sz;


    lpSize->cx = 0;
    lpSize->cy = 0;

    btnPtr = infoPtr->buttons;
    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
        TOOLBAR_MeasureString(hwnd,i,&sz);
        if (sz.cx > lpSize->cx)
            lpSize->cx = sz.cx;
        if (sz.cy > lpSize->cy)
            lpSize->cy = sz.cy;
    }

    TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
}

456 457 458 459 460 461 462 463 464 465 466
/***********************************************************************
* 		TOOLBAR_WrapToolbar
*
* This function walks through the buttons and seperators in the 
* toolbar, and sets the TBSTATE_WRAP flag only on those items where 
* wrapping should occur based on the width of the toolbar window.  
* It does *not* calculate button placement itself.  That task 
* takes place in TOOLBAR_CalcToolbar. If the program wants to manage 
* the toolbar wrapping on it's own, it can use the TBSTYLE_WRAPPABLE 
* flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
*/ 
Alexandre Julliard's avatar
Alexandre Julliard committed
467

Alexandre Julliard's avatar
Alexandre Julliard committed
468
static void
469
TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
Alexandre Julliard's avatar
Alexandre Julliard committed
470
{
471
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
472 473 474 475 476 477 478 479 480 481 482 483 484 485
    TBUTTON_INFO *btnPtr;
    INT x, cx, i, j;
    RECT rc;
    BOOL bWrap, bButtonWrap;

    /* 	When the toolbar window style is not TBSTYLE_WRAPABLE,	*/ 
    /*	no layout is necessary. Applications may use this style */
    /*	to perform their own layout on the toolbar. 		*/
    if( !(dwStyle & TBSTYLE_WRAPABLE) )
	return;

    btnPtr = infoPtr->buttons;
    x  = infoPtr->nIndent;

486 487 488 489
    /* this can get the parents width, to know how far we can extend
     * this toolbar.  We cannot use its height, as there may be multiple
     * toolbars in a rebar control
     */
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
    GetClientRect( GetParent(hwnd), &rc );
    infoPtr->nWidth = rc.right - rc.left;
    bButtonWrap = FALSE;

    for (i = 0; i < infoPtr->nNumButtons; i++ )
    {
	bWrap = FALSE;
	btnPtr[i].fsState &= ~TBSTATE_WRAP;
	
	if (btnPtr[i].fsState & TBSTATE_HIDDEN)
	    continue;

	/* UNDOCUMENTED: If a separator has a non zero bitmap index, */
	/* it is the actual width of the separator. This is used for */
	/* custom controls in toolbars.                              */
	if (btnPtr[i].fsStyle & TBSTYLE_SEP)
	    cx = (btnPtr[i].iBitmap > 0) ?  
			btnPtr[i].iBitmap : SEPARATOR_WIDTH;
	else
	    cx = infoPtr->nButtonWidth;

	/* Two or more adjacent separators form a separator group.   */ 
	/* The first separator in a group should be wrapped to the   */
	/* next row if the previous wrapping is on a button.	     */
	if( bButtonWrap &&
		(btnPtr[i].fsStyle & TBSTYLE_SEP) && 
		(i + 1 < infoPtr->nNumButtons ) &&
		(btnPtr[i + 1].fsStyle & TBSTYLE_SEP) ) 
	{
	    btnPtr[i].fsState |= TBSTATE_WRAP;
	    x = infoPtr->nIndent;
	    i++;
	    bButtonWrap = FALSE;
	    continue;
	}

	/* The layout makes sure the bitmap is visible, but not the button. */
	if ( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2 
		 > infoPtr->nWidth ) 
	{
	    BOOL bFound = FALSE;

	    /* 	If the current button is a separator and not hidden,  */ 
	    /*	go to the next until it reaches a non separator.      */
	    /*	Wrap the last separator if it is before a button.     */
	    while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) || 
			(btnPtr[i].fsState & TBSTATE_HIDDEN) ) && 
			i < infoPtr->nNumButtons )
	    {
		i++;
		bFound = TRUE;
	    }
    
	    if( bFound && i < infoPtr->nNumButtons )
	    {
		i--;
		btnPtr[i].fsState |= TBSTATE_WRAP;
		x = infoPtr->nIndent;
		bButtonWrap = FALSE;
		continue;
	    }
	    else if ( i >= infoPtr->nNumButtons)
		break;

	    /* 	If the current button is not a separator, find the last  */ 
	    /*	separator and wrap it.   				 */
	    for ( j = i - 1; j >= 0  &&  !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
	    {
		if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
			!(btnPtr[j].fsState & TBSTATE_HIDDEN))
		{
		    bFound = TRUE; 
		    i = j; 
		    x = infoPtr->nIndent;
		    btnPtr[j].fsState |= TBSTATE_WRAP;
		    bButtonWrap = FALSE; 
		    break;
		}
	    }

	    /* 	If no separator available for wrapping, wrap one of 	*/
	    /*  non-hidden previous button.  			     	*/
	    if (!bFound)
	    {
		for ( j = i - 1; 
			j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
		{
		    if (btnPtr[j].fsState & TBSTATE_HIDDEN) 
			continue;

		    bFound = TRUE; 
		    i = j; 
		    x = infoPtr->nIndent;
		    btnPtr[j].fsState |= TBSTATE_WRAP;
		    bButtonWrap = TRUE;
		    break;
		}
	    }

	    /* If all above failed, wrap the current button. */
	    if (!bFound)  
	    {
		btnPtr[i].fsState |= TBSTATE_WRAP;
		bFound = TRUE;
		x = infoPtr->nIndent;
		if (btnPtr[i].fsState & TBSTYLE_SEP )
		    bButtonWrap = FALSE;
		else
		    bButtonWrap = TRUE;
	    }		    
	}
	else
	    x += cx;
    }
}
											
/***********************************************************************
* 		TOOLBAR_CalcToolbar
*
* This function calculates button and separator placement. It first 
* calculates the button sizes, gets the toolbar window width and then 
* calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap 
* on. It assigns a new location to each item and sends this location to
* the tooltip window if appropriate. Finally, it updates the rcBound 
* rect and calculates the new required toolbar window height. 
*/  

static void
TOOLBAR_CalcToolbar (HWND hwnd)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
621
    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
622
    TBUTTON_INFO *btnPtr;
623
    INT i, nRows, nSepRows;
624 625
    INT x, y, cx, cy;
    SIZE  sizeString;
626
    BOOL bWrap;
Alexandre Julliard's avatar
Alexandre Julliard committed
627

628
    TOOLBAR_CalcStrings (hwnd, &sizeString);
Alexandre Julliard's avatar
Alexandre Julliard committed
629

630 631 632 633 634
    if (dwStyle & TBSTYLE_LIST) {
	infoPtr->nButtonHeight = max(infoPtr->nBitmapHeight, sizeString.cy) + 6;
	infoPtr->nButtonWidth = infoPtr->nBitmapWidth + sizeString.cx + 6;
    }
    else {
635 636 637 638
    BOOL usesBitmaps = FALSE;
    INT i;

    for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
639
	if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
640 641
	    usesBitmaps = TRUE;

642
    if (sizeString.cy > 0) {
643 644 645 646
        if (usesBitmaps)
	  infoPtr->nButtonHeight = sizeString.cy + infoPtr->nBitmapHeight + 6;
        else 
          infoPtr->nButtonHeight = sizeString.cy + 6;
647
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
648 649
    else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
	infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
Alexandre Julliard's avatar
Alexandre Julliard committed
650 651 652

    if (sizeString.cx > infoPtr->nBitmapWidth)
	infoPtr->nButtonWidth = sizeString.cx + 6;
Alexandre Julliard's avatar
Alexandre Julliard committed
653 654
    else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
	infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
655
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
656

657 658 659 660 661
    if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
        infoPtr->nButtonWidth = infoPtr->cxMin;
    if ( infoPtr->cxMax >= 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
        infoPtr->nButtonWidth = infoPtr->cxMax;

662
    TOOLBAR_WrapToolbar( hwnd, dwStyle );
663

Alexandre Julliard's avatar
Alexandre Julliard committed
664
    x  = infoPtr->nIndent;
665
    y  = (dwStyle & TBSTYLE_FLAT) ? 0 : TOP_BORDER;
666

667 668 669 670 671
   /*
    * We wills et the height below, and we set the width on entry 
    * so we do not reset them here.. 
    */
#if 0
672 673 674 675
    GetClientRect( hwnd, &rc );
    /* get initial values for toolbar */
    infoPtr->nWidth  = rc.right - rc.left;
    infoPtr->nHeight = rc.bottom - rc.top;
676
#endif
677 678

    /* from above, minimum is a button, and possible text */
Alexandre Julliard's avatar
Alexandre Julliard committed
679
    cx = infoPtr->nButtonWidth;
680
    /* cannot use just ButtonHeight, we may have no buttons! */
681 682
    if (infoPtr->nNumButtons > 0)
      infoPtr->nHeight = infoPtr->nButtonHeight;
683 684
    cy = infoPtr->nHeight;

685
    nRows = nSepRows = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
686 687 688 689 690

    infoPtr->rcBound.top = y;
    infoPtr->rcBound.left = x;
    infoPtr->rcBound.bottom = y + cy;
    infoPtr->rcBound.right = x;
Alexandre Julliard's avatar
Alexandre Julliard committed
691 692

    btnPtr = infoPtr->buttons;
693 694 695 696 697 698

    /* do not base height/width on parent, if the parent is a */
    /* rebar control it could have multiple rows of toolbars  */
/*    GetClientRect( GetParent(hwnd), &rc ); */
/*    cx = rc.right - rc.left; */
/*    cy = rc.bottom - rc.top; */
Alexandre Julliard's avatar
Alexandre Julliard committed
699

700 701 702 703 704
    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
    {
	bWrap = FALSE;
	if (btnPtr->fsState & TBSTATE_HIDDEN)
	{
705
	    SetRectEmpty (&btnPtr->rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
706
	    continue;
707 708 709 710 711
	}

	    /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
	    /* it is the actual width of the separator. This is used for */
	    /* custom controls in toolbars.                              */
712
	if (btnPtr->fsStyle & TBSTYLE_SEP)
713 714
		cx = (btnPtr->iBitmap > 0) ?
		     btnPtr->iBitmap : SEPARATOR_WIDTH;
715
	else {
716 717 718 719 720 721 722 723
            if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE) 
            {
              SIZE sz;
              TOOLBAR_MeasureString(hwnd,i,&sz);
              cx = sz.cx + 6;
            }
            else
	      cx = infoPtr->nButtonWidth;
724 725
	}
	cy = infoPtr->nHeight;
726

727
	if (btnPtr->fsState & TBSTATE_WRAP )
728 729
		    bWrap = TRUE;

730
	SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
Alexandre Julliard's avatar
Alexandre Julliard committed
731

Alexandre Julliard's avatar
Alexandre Julliard committed
732 733 734 735 736 737
	if (infoPtr->rcBound.left > x)
	    infoPtr->rcBound.left = x;
	if (infoPtr->rcBound.right < x + cx)
	    infoPtr->rcBound.right = x + cx;
	if (infoPtr->rcBound.bottom < y + cy)
	    infoPtr->rcBound.bottom = y + cy;
Alexandre Julliard's avatar
Alexandre Julliard committed
738

739 740 741
	/* Set the toolTip only for non-hidden, non-separator button */
	if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP )) 
	{
742
	    TTTOOLINFOA ti;
Alexandre Julliard's avatar
Alexandre Julliard committed
743

744 745
	    ZeroMemory (&ti, sizeof(TTTOOLINFOA));
	    ti.cbSize = sizeof(TTTOOLINFOA);
746
	    ti.hwnd = hwnd;
Alexandre Julliard's avatar
Alexandre Julliard committed
747 748
	    ti.uId = btnPtr->idCommand;
	    ti.rect = btnPtr->rect;
749
	    SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
Alexandre Julliard's avatar
Alexandre Julliard committed
750 751 752
			    0, (LPARAM)&ti);
	}

753 754 755 756 757 758
	/* btnPtr->nRow is zero based. The space between the rows is 	*/
	/* also considered as a row. 					*/
	btnPtr->nRow = nRows + nSepRows;
	if( bWrap )
	{
	    if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
Alexandre Julliard's avatar
Alexandre Julliard committed
759
	    y += cy;
760 761 762 763 764 765 766 767 768 769 770 771 772
	    else 
	    {   
		/* UNDOCUMENTED: If a separator has a non zero bitmap index, */
		/* it is the actual width of the separator. This is used for */
		/* custom controls in toolbars. 			     */
		y += cy + ( (btnPtr->iBitmap > 0 ) ? 
			btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3; 
	     
		/* nSepRows is used to calculate the extra height follwoing  */ 	 
		/* the last row.					     */
		nSepRows++;
	    }
	    x = infoPtr->nIndent;
Alexandre Julliard's avatar
Alexandre Julliard committed
773 774
		nRows++;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
775
	else
Alexandre Julliard's avatar
Alexandre Julliard committed
776
	    x += cx;
Alexandre Julliard's avatar
Alexandre Julliard committed
777
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
778

779 780 781 782 783 784
    /* infoPtr->nRows is the number of rows on the toolbar */
    infoPtr->nRows = nRows + nSepRows + 1;

    /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following 	*/
    /* the last row. 							*/
    infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight + 
785
		       	nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
786 787
			nSepRows * (infoPtr->nBitmapHeight + 1) + 
			BOTTOM_BORDER; 
788
    TRACE("toolbar height %d\n", infoPtr->nHeight);
Alexandre Julliard's avatar
Alexandre Julliard committed
789 790 791
}


792
static INT
793
TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
Alexandre Julliard's avatar
Alexandre Julliard committed
794
{
795
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
796
    TBUTTON_INFO *btnPtr;
797
    INT i;
Alexandre Julliard's avatar
Alexandre Julliard committed
798 799
    
    btnPtr = infoPtr->buttons;
Alexandre Julliard's avatar
Alexandre Julliard committed
800
    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
Alexandre Julliard's avatar
Alexandre Julliard committed
801 802 803
	if (btnPtr->fsState & TBSTATE_HIDDEN)
	    continue;

Alexandre Julliard's avatar
Alexandre Julliard committed
804
	if (btnPtr->fsStyle & TBSTYLE_SEP) {
805
	    if (PtInRect (&btnPtr->rect, *lpPt)) {
806
		TRACE(" ON SEPARATOR %d!\n", i);
Alexandre Julliard's avatar
Alexandre Julliard committed
807 808 809 810
		return -i;
	    }
	}
	else {
811
	    if (PtInRect (&btnPtr->rect, *lpPt)) {
812
		TRACE(" ON BUTTON %d!\n", i);
Alexandre Julliard's avatar
Alexandre Julliard committed
813 814 815 816 817
		return i;
	    }
	}
    }

818
    TRACE(" NOWHERE!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
819 820 821 822
    return -1;
}


823 824
static INT
TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand)
Alexandre Julliard's avatar
Alexandre Julliard committed
825 826
{
    TBUTTON_INFO *btnPtr;
827
    INT i;
Alexandre Julliard's avatar
Alexandre Julliard committed
828 829

    btnPtr = infoPtr->buttons;
Alexandre Julliard's avatar
Alexandre Julliard committed
830
    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
Alexandre Julliard's avatar
Alexandre Julliard committed
831
	if (btnPtr->idCommand == idCommand) {
832
	    TRACE("command=%d index=%d\n", idCommand, i);
Alexandre Julliard's avatar
Alexandre Julliard committed
833
	    return i;
Alexandre Julliard's avatar
Alexandre Julliard committed
834
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
835
    }
836
    TRACE("no index found for command=%d\n", idCommand);
Alexandre Julliard's avatar
Alexandre Julliard committed
837 838 839 840
    return -1;
}


841 842
static INT
TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
Alexandre Julliard's avatar
Alexandre Julliard committed
843 844
{
    TBUTTON_INFO *btnPtr;
845
    INT nRunIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882

    if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
	return -1;

    /* check index button */
    btnPtr = &infoPtr->buttons[nIndex];
    if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
	if (btnPtr->fsState & TBSTATE_CHECKED)
	    return nIndex;
    }

    /* check previous buttons */
    nRunIndex = nIndex - 1;
    while (nRunIndex >= 0) {
	btnPtr = &infoPtr->buttons[nRunIndex];
	if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
	    if (btnPtr->fsState & TBSTATE_CHECKED)
		return nRunIndex;
	}
	else
	    break;
	nRunIndex--;
    }

    /* check next buttons */
    nRunIndex = nIndex + 1;
    while (nRunIndex < infoPtr->nNumButtons) {
	btnPtr = &infoPtr->buttons[nRunIndex];	
	if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
	    if (btnPtr->fsState & TBSTATE_CHECKED)
		return nRunIndex;
	}
	else
	    break;
	nRunIndex++;
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
883 884 885 886
    return -1;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
887
static VOID
888 889
TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
		    WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
890
{
891
    MSG msg;
Alexandre Julliard's avatar
Alexandre Julliard committed
892 893 894 895 896 897 898 899 900

    msg.hwnd = hwndMsg;
    msg.message = uMsg;
    msg.wParam = wParam;
    msg.lParam = lParam;
    msg.time = GetMessageTime ();
    msg.pt.x = LOWORD(GetMessagePos ());
    msg.pt.y = HIWORD(GetMessagePos ());

901
    SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
Alexandre Julliard's avatar
Alexandre Julliard committed
902 903
}

904 905 906 907 908

/***********************************************************************
 * TOOLBAR_CustomizeDialogProc
 * This function implements the toolbar customization dialog.
 */
909
static BOOL WINAPI
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongA (hwnd, DWL_USER);
    static HDSA hDsa = NULL;

    switch (uMsg)
    {
	case WM_INITDIALOG:
	    infoPtr = (TOOLBAR_INFO *)lParam;
	    SetWindowLongA (hwnd, DWL_USER, (DWORD)infoPtr);

	    hDsa = DSA_Create (sizeof(TBUTTON_INFO), 5);

	    if (infoPtr)
	    {
		TBUTTON_INFO *btnPtr;
		INT i;

		/* insert 'virtual' separator button into 'available buttons' list */
		SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");

		/* copy all buttons and append them to the right listbox */		
		btnPtr = infoPtr->buttons;
		for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
		{
		    DSA_InsertItem (hDsa, i, btnPtr);

937
		    /* FIXME: hidden buttons appear in the 'toolbar buttons' list too */
938 939 940 941 942 943 944 945 946 947
		    if (btnPtr->fsState & TBSTATE_HIDDEN)
		    {
			SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
		    }
		    else
		    {
			SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
		    }
		}

948
		/* append 'virtual' separator button to the 'toolbar buttons' list */
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
		/* TODO */
	    }
	    return TRUE;

	case WM_CLOSE:
	    EndDialog(hwnd, FALSE);
	    return TRUE;

	case WM_COMMAND:
	    switch (LOWORD(wParam))
	    {
		case IDCANCEL:
		    EndDialog(hwnd, FALSE);
		    break;
	    }
	    return TRUE;

	case WM_DESTROY:
	    if (hDsa)
		DSA_Destroy (hDsa);
	    return TRUE;

	case WM_DRAWITEM:
	    if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
	    {
		LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
975
		TBUTTON_INFO btnPtr;
976 977 978 979 980 981 982
		RECT rcButton;
		RECT rcText;
		HPEN hOldPen;
		HBRUSH hOldBrush;
		COLORREF oldText = 0;
		COLORREF oldBk = 0;

983
		FIXME("action: %x itemState: %x\n",
984 985
		      lpdis->itemAction, lpdis->itemState);		

986 987
		DSA_GetItem (hDsa, 0 /*lpdis->itemID*/, &btnPtr);

988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
		if (lpdis->itemState & ODS_FOCUS)
		{
		    oldBk = SetBkColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
		    oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
		}

		hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
		hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));

		/* fill background rectangle */
		Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
			   lpdis->rcItem.right, lpdis->rcItem.bottom);

		/* calculate button and text rectangles */
		CopyRect (&rcButton, &lpdis->rcItem);
		InflateRect (&rcButton, -1, -1);
		CopyRect (&rcText, &rcButton);
		rcButton.right = rcButton.left + infoPtr->nBitmapWidth + 6;
		rcText.left = rcButton.right + 2;

		/* draw focus rectangle */
		if (lpdis->itemState & ODS_FOCUS)
		    DrawFocusRect (lpdis->hDC, &lpdis->rcItem);

		/* draw button */
		DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);

1015
		/* draw image and text */
1016
		if (wParam == IDC_AVAILBTN_LBOX && lpdis->itemID == 0)
1017 1018
		{
		    /* virtual separator in the 'available' list */
1019 1020
		    DrawTextA (lpdis->hDC, "Separator", -1, &rcText,
			       DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1021 1022 1023 1024
		}
		else
		{
		    /* real button */
1025 1026 1027 1028 1029 1030 1031

		    ImageList_Draw (infoPtr->himlDef, btnPtr.iBitmap, lpdis->hDC,
				    rcButton.left+1, rcButton.top+1, ILD_NORMAL);

		    DrawTextW (lpdis->hDC,  infoPtr->strings[btnPtr.iString], -1, &rcText,
			       DT_LEFT | DT_VCENTER | DT_SINGLELINE);

1032
		}
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054

		if (lpdis->itemState & ODS_FOCUS)
		{
		    SetBkColor (lpdis->hDC, oldBk);
		    SetTextColor (lpdis->hDC, oldText);
		}

		SelectObject (lpdis->hDC, hOldBrush);
		SelectObject (lpdis->hDC, hOldPen);

		return TRUE;
	    }
	    return FALSE;

	case WM_MEASUREITEM:
	    if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
	    {
		MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;

		if (infoPtr)
		    lpmis->itemHeight = infoPtr->nBitmapHeight + 8;
		else
1055
		    lpmis->itemHeight = 15 + 8; /* default height */
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066

		return TRUE;
	    }
	    return FALSE;

	default:
	    return FALSE;
    }
}


1067 1068 1069 1070
/***********************************************************************
 * TOOLBAR_AddBitmap:  Add the bitmaps to the default image list.
 *
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
1071
static LRESULT
1072
TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1073
{
1074
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1075
    LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
1076
    INT nIndex = 0, nButtons, nCount;
1077
    HBITMAP hbmLoad;
Alexandre Julliard's avatar
Alexandre Julliard committed
1078

1079
    TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
1080
    if (!lpAddBmp)
Alexandre Julliard's avatar
Alexandre Julliard committed
1081 1082
	return -1;

1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
    if (lpAddBmp->hInst == HINST_COMMCTRL)
    {
	if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
	    nButtons = 15;
	else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
	    nButtons = 13;
	else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
	    nButtons = 5;
	else
	    return -1;
1093

1094
	TRACE ("adding %d internal bitmaps!\n", nButtons);
1095

1096
	/* Windows resize all the buttons to the size of a newly added standard image */
1097
	if (lpAddBmp->nID & 1) 
1098
	{
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
	    /* large icons */
	    SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
			  MAKELPARAM((WORD)26, (WORD)26));
	    SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
			  MAKELPARAM((WORD)33, (WORD)33));
	}	
	else 
	{
	    /* small icons */
	    SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
			  MAKELPARAM((WORD)16, (WORD)16));
	    SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
			  MAKELPARAM((WORD)22, (WORD)22));
1112
	}
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
	
	TOOLBAR_CalcToolbar (hwnd);
    }
    else
    {
	nButtons = (INT)wParam;
	if (nButtons <= 0)
	    return -1;
	
	TRACE ("adding %d bitmaps!\n", nButtons);
    }
    
    if (!(infoPtr->himlDef)) {
	/* create new default image list */
	TRACE ("creating default image list!\n");
1128

1129
	infoPtr->himlDef =
1130
	    ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
1131 1132
			      ILC_COLOR | ILC_MASK, nButtons, 2);
	infoPtr->himlInt = infoPtr->himlDef;
Alexandre Julliard's avatar
Alexandre Julliard committed
1133 1134
    }

1135 1136
    nCount = ImageList_GetImageCount(infoPtr->himlDef);

1137 1138 1139
    /* Add bitmaps to the default image list */
    if (lpAddBmp->hInst == (HINSTANCE)0)
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
1140
	nIndex = 
1141
	    ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
Alexandre Julliard's avatar
Alexandre Julliard committed
1142
				 CLR_DEFAULT);
Alexandre Julliard's avatar
Alexandre Julliard committed
1143
    }
1144 1145
    else if (lpAddBmp->hInst == HINST_COMMCTRL)
    {
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
	/* Add system bitmaps */
	switch (lpAddBmp->nID)
    {
	    case IDB_STD_SMALL_COLOR:
		hbmLoad = LoadBitmapA (COMCTL32_hModule,
				       MAKEINTRESOURCEA(IDB_STD_SMALL));
		nIndex = ImageList_AddMasked (infoPtr->himlDef,
					      hbmLoad, CLR_DEFAULT);
		DeleteObject (hbmLoad);
		break;

	    case IDB_STD_LARGE_COLOR:
		hbmLoad = LoadBitmapA (COMCTL32_hModule,
				       MAKEINTRESOURCEA(IDB_STD_LARGE));
		nIndex = ImageList_AddMasked (infoPtr->himlDef,
					      hbmLoad, CLR_DEFAULT);
		DeleteObject (hbmLoad);
		break;

	    case IDB_VIEW_SMALL_COLOR:
		hbmLoad = LoadBitmapA (COMCTL32_hModule,
				       MAKEINTRESOURCEA(IDB_VIEW_SMALL));
		nIndex = ImageList_AddMasked (infoPtr->himlDef,
					      hbmLoad, CLR_DEFAULT);
		DeleteObject (hbmLoad);
		break;

	    case IDB_VIEW_LARGE_COLOR:
		hbmLoad = LoadBitmapA (COMCTL32_hModule,
				       MAKEINTRESOURCEA(IDB_VIEW_LARGE));
		nIndex = ImageList_AddMasked (infoPtr->himlDef,
					      hbmLoad, CLR_DEFAULT);
		DeleteObject (hbmLoad);
		break;

	    case IDB_HIST_SMALL_COLOR:
		hbmLoad = LoadBitmapA (COMCTL32_hModule,
				       MAKEINTRESOURCEA(IDB_HIST_SMALL));
		nIndex = ImageList_AddMasked (infoPtr->himlDef,
					      hbmLoad, CLR_DEFAULT);
		DeleteObject (hbmLoad);
		break;

	    case IDB_HIST_LARGE_COLOR:
		hbmLoad = LoadBitmapA (COMCTL32_hModule,
				       MAKEINTRESOURCEA(IDB_HIST_LARGE));
		nIndex = ImageList_AddMasked (infoPtr->himlDef,
					      hbmLoad, CLR_DEFAULT);
		DeleteObject (hbmLoad);
		break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1196

1197
	    default:
1198
	nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1199 1200 1201
		ERR ("invalid imagelist!\n");
		break;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1202
    }
1203 1204
    else
    {
1205 1206 1207
	hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
	nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
	DeleteObject (hbmLoad);
Alexandre Julliard's avatar
Alexandre Julliard committed
1208 1209
    }

1210 1211 1212 1213 1214 1215
    if (nIndex != -1)
    {
       INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);

       if (infoPtr->nNumBitmaps + nButtons != imagecount)
       {
Patrik Stridvall's avatar
Patrik Stridvall committed
1216
         WARN("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",
1217 1218 1219 1220 1221 1222 1223 1224
	      infoPtr->nNumBitmaps, nCount, imagecount - nCount,
	      infoPtr->nNumBitmaps+nButtons,imagecount);

	 infoPtr->nNumBitmaps = imagecount;
       }
       else
         infoPtr->nNumBitmaps += nButtons;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1225

Alexandre Julliard's avatar
Alexandre Julliard committed
1226
    return nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
1227 1228 1229 1230
}


static LRESULT
1231
TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1232
{
1233
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1234
    LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1235
    INT nOldButtons, nNewButtons, nAddButtons, nCount;
Alexandre Julliard's avatar
Alexandre Julliard committed
1236

1237
    TRACE("adding %d buttons!\n", wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1238

1239
    nAddButtons = (UINT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
1240 1241 1242 1243 1244
    nOldButtons = infoPtr->nNumButtons;
    nNewButtons = nOldButtons + nAddButtons;

    if (infoPtr->nNumButtons == 0) {
	infoPtr->buttons =
Alexandre Julliard's avatar
Alexandre Julliard committed
1245
	    COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
Alexandre Julliard's avatar
Alexandre Julliard committed
1246 1247 1248 1249
    }
    else {
	TBUTTON_INFO *oldButtons = infoPtr->buttons;
	infoPtr->buttons =
Alexandre Julliard's avatar
Alexandre Julliard committed
1250
	    COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
Alexandre Julliard's avatar
Alexandre Julliard committed
1251 1252
	memcpy (&infoPtr->buttons[0], &oldButtons[0],
		nOldButtons * sizeof(TBUTTON_INFO));
Alexandre Julliard's avatar
Alexandre Julliard committed
1253
        COMCTL32_Free (oldButtons);
Alexandre Julliard's avatar
Alexandre Julliard committed
1254 1255 1256 1257
    }

    infoPtr->nNumButtons = nNewButtons;

Alexandre Julliard's avatar
Alexandre Julliard committed
1258
    /* insert new button data */
Alexandre Julliard's avatar
Alexandre Julliard committed
1259
    for (nCount = 0; nCount < nAddButtons; nCount++) {
Alexandre Julliard's avatar
Alexandre Julliard committed
1260 1261 1262 1263 1264 1265 1266
	TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
	btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
	btnPtr->idCommand = lpTbb[nCount].idCommand;
	btnPtr->fsState   = lpTbb[nCount].fsState;
	btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
	btnPtr->dwData    = lpTbb[nCount].dwData;
	btnPtr->iString   = lpTbb[nCount].iString;
1267
	btnPtr->bHot      = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1268 1269

	if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
1270
	    TTTOOLINFOA ti;
Alexandre Julliard's avatar
Alexandre Julliard committed
1271

1272 1273
	    ZeroMemory (&ti, sizeof(TTTOOLINFOA));
	    ti.cbSize   = sizeof (TTTOOLINFOA);
1274
	    ti.hwnd     = hwnd;
Alexandre Julliard's avatar
Alexandre Julliard committed
1275
	    ti.uId      = btnPtr->idCommand;
Alexandre Julliard's avatar
Alexandre Julliard committed
1276
	    ti.hinst    = 0;
1277
	    ti.lpszText = LPSTR_TEXTCALLBACKA;
Alexandre Julliard's avatar
Alexandre Julliard committed
1278

1279
	    SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
Alexandre Julliard's avatar
Alexandre Julliard committed
1280 1281
			    0, (LPARAM)&ti);
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1282 1283
    }

1284
    TOOLBAR_CalcToolbar (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1285

1286
    InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1287 1288 1289 1290 1291

    return TRUE;
}


1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
static LRESULT
TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
    INT nOldButtons, nNewButtons, nAddButtons, nCount;

    TRACE("adding %d buttons!\n", wParam);

    nAddButtons = (UINT)wParam;
    nOldButtons = infoPtr->nNumButtons;
    nNewButtons = nOldButtons + nAddButtons;

    if (infoPtr->nNumButtons == 0) {
	infoPtr->buttons =
	    COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
    }
    else {
	TBUTTON_INFO *oldButtons = infoPtr->buttons;
	infoPtr->buttons =
	    COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
	memcpy (&infoPtr->buttons[0], &oldButtons[0],
		nOldButtons * sizeof(TBUTTON_INFO));
        COMCTL32_Free (oldButtons);
    }

    infoPtr->nNumButtons = nNewButtons;

    /* insert new button data */
    for (nCount = 0; nCount < nAddButtons; nCount++) {
	TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
	btnPtr->iBitmap   = lpTbb[nCount].iBitmap;
	btnPtr->idCommand = lpTbb[nCount].idCommand;
	btnPtr->fsState   = lpTbb[nCount].fsState;
	btnPtr->fsStyle   = lpTbb[nCount].fsStyle;
	btnPtr->dwData    = lpTbb[nCount].dwData;
	btnPtr->iString   = lpTbb[nCount].iString;
	btnPtr->bHot      = FALSE;

	if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
	    TTTOOLINFOW ti;

	    ZeroMemory (&ti, sizeof(TTTOOLINFOW));
	    ti.cbSize   = sizeof (TTTOOLINFOW);
	    ti.hwnd     = hwnd;
	    ti.uId      = btnPtr->idCommand;
	    ti.hinst    = 0;
	    ti.lpszText = LPSTR_TEXTCALLBACKW;

	    SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
			    0, (LPARAM)&ti);
	}
    }

    TOOLBAR_CalcToolbar (hwnd);

    InvalidateRect(hwnd, NULL, FALSE);

    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1352 1353 1354


static LRESULT
1355
TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1356
{
1357
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1358
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
1359

1360
    if ((wParam) && (HIWORD(lParam) == 0)) {
Alexandre Julliard's avatar
Alexandre Julliard committed
1361
	char szString[256];
1362
	INT len;
1363
	TRACE("adding string from resource!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
1364

1365
	len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
Alexandre Julliard's avatar
Alexandre Julliard committed
1366 1367
			     szString, 256);

1368
	TRACE("len=%d \"%s\"\n", len, szString);
Alexandre Julliard's avatar
Alexandre Julliard committed
1369 1370 1371
	nIndex = infoPtr->nNumStrings;
	if (infoPtr->nNumStrings == 0) {
	    infoPtr->strings =
1372
		COMCTL32_Alloc (sizeof(LPWSTR));
Alexandre Julliard's avatar
Alexandre Julliard committed
1373 1374
	}
	else {
1375
	    LPWSTR *oldStrings = infoPtr->strings;
Alexandre Julliard's avatar
Alexandre Julliard committed
1376
	    infoPtr->strings =
1377
		COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
Alexandre Julliard's avatar
Alexandre Julliard committed
1378
	    memcpy (&infoPtr->strings[0], &oldStrings[0],
1379
		    sizeof(LPWSTR) * infoPtr->nNumStrings);
Alexandre Julliard's avatar
Alexandre Julliard committed
1380
	    COMCTL32_Free (oldStrings);
Alexandre Julliard's avatar
Alexandre Julliard committed
1381 1382 1383
	}

	infoPtr->strings[infoPtr->nNumStrings] =
1384 1385
	    COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
	lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], szString);
Alexandre Julliard's avatar
Alexandre Julliard committed
1386 1387 1388
	infoPtr->nNumStrings++;
    }
    else {
1389
	LPSTR p = (LPSTR)lParam;
1390
	INT len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1391

1392 1393
	if (p == NULL)
	    return -1;
1394
	TRACE("adding string(s) from array!\n");
1395

Alexandre Julliard's avatar
Alexandre Julliard committed
1396 1397
	nIndex = infoPtr->nNumStrings;
	while (*p) {
1398
	    len = lstrlenA (p);
1399
	    TRACE("len=%d \"%s\"\n", len, p);
Alexandre Julliard's avatar
Alexandre Julliard committed
1400 1401 1402

	    if (infoPtr->nNumStrings == 0) {
		infoPtr->strings =
1403
		    COMCTL32_Alloc (sizeof(LPWSTR));
Alexandre Julliard's avatar
Alexandre Julliard committed
1404 1405
	    }
	    else {
1406
		LPWSTR *oldStrings = infoPtr->strings;
Alexandre Julliard's avatar
Alexandre Julliard committed
1407
		infoPtr->strings =
1408
		    COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
Alexandre Julliard's avatar
Alexandre Julliard committed
1409
		memcpy (&infoPtr->strings[0], &oldStrings[0],
1410
			sizeof(LPWSTR) * infoPtr->nNumStrings);
Alexandre Julliard's avatar
Alexandre Julliard committed
1411
		COMCTL32_Free (oldStrings);
Alexandre Julliard's avatar
Alexandre Julliard committed
1412 1413 1414
	    }

	    infoPtr->strings[infoPtr->nNumStrings] =
1415 1416
		COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
	    lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
Alexandre Julliard's avatar
Alexandre Julliard committed
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
	    infoPtr->nNumStrings++;

	    p += (len+1);
	}
    }

    return nIndex;
}


1427
static LRESULT
1428
TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1429
{
1430
#define MAX_RESOURCE_STRING_LENGTH 512
1431
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1432
    INT nIndex;
1433 1434

    if ((wParam) && (HIWORD(lParam) == 0)) {
1435
	WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
1436
	INT len;
1437
	TRACE("adding string from resource!\n");
1438

1439
	len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
1440
			     szString, MAX_RESOURCE_STRING_LENGTH);
1441

1442
	TRACE("len=%d \"%s\"\n", len, debugstr_w(szString));
1443 1444 1445 1446 1447 1448 1449
	TRACE("First char: 0x%x\n", *szString);
	if (szString[0] == L'|')
	{
	    PWSTR p = szString + 1;
		
	    nIndex = infoPtr->nNumStrings;
	    while (*p != L'|') {
1450

1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
	    if (infoPtr->nNumStrings == 0) {
		infoPtr->strings =
		    COMCTL32_Alloc (sizeof(LPWSTR));
	    }
	    else {
		LPWSTR *oldStrings = infoPtr->strings;
		infoPtr->strings =
		    COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
		memcpy (&infoPtr->strings[0], &oldStrings[0],
			sizeof(LPWSTR) * infoPtr->nNumStrings);
		COMCTL32_Free (oldStrings);
	    }

	    len = COMCTL32_StrChrW (p, L'|') - p;
	    TRACE("len=%d \"%s\"\n", len, debugstr_w(p));
	    infoPtr->strings[infoPtr->nNumStrings] =
		COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1468
	    lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len);
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
	    infoPtr->nNumStrings++;

		p += (len+1);
	    }
	}
	else
	{
            nIndex = infoPtr->nNumStrings;
            if (infoPtr->nNumStrings == 0) {
                infoPtr->strings =
                    COMCTL32_Alloc (sizeof(LPWSTR));
            }
            else {
                LPWSTR *oldStrings = infoPtr->strings;
                infoPtr->strings =
                    COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
                memcpy (&infoPtr->strings[0], &oldStrings[0],
                        sizeof(LPWSTR) * infoPtr->nNumStrings);
                COMCTL32_Free (oldStrings);
            }

            infoPtr->strings[infoPtr->nNumStrings] =
                COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1492
            strcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
1493 1494
            infoPtr->nNumStrings++;
        }
1495 1496 1497
    }
    else {
	LPWSTR p = (LPWSTR)lParam;
1498
	INT len;
1499 1500 1501

	if (p == NULL)
	    return -1;
1502
	TRACE("adding string(s) from array!\n");
1503 1504
	nIndex = infoPtr->nNumStrings;
	while (*p) {
1505
	    len = lstrlenW (p);
1506

1507
	    TRACE("len=%d \"%s\"\n", len, debugstr_w(p));
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
	    if (infoPtr->nNumStrings == 0) {
		infoPtr->strings =
		    COMCTL32_Alloc (sizeof(LPWSTR));
	    }
	    else {
		LPWSTR *oldStrings = infoPtr->strings;
		infoPtr->strings =
		    COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
		memcpy (&infoPtr->strings[0], &oldStrings[0],
			sizeof(LPWSTR) * infoPtr->nNumStrings);
		COMCTL32_Free (oldStrings);
	    }

	    infoPtr->strings[infoPtr->nNumStrings] =
		COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1523
	    strcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
1524 1525 1526 1527 1528 1529 1530 1531
	    infoPtr->nNumStrings++;

	    p += (len+1);
	}
    }

    return nIndex;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1532 1533 1534


static LRESULT
1535
TOOLBAR_AutoSize (HWND hwnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
1536
{
1537 1538
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1539
    RECT parent_rect;
1540
    RECT window_rect;
1541
    HWND parent;
1542
    INT  x, y;
1543
    INT  cx, cy;
1544
    UINT uPosFlags = SWP_NOZORDER;
Alexandre Julliard's avatar
Alexandre Julliard committed
1545

1546
    TRACE("resize forced, style=%lx!\n", dwStyle);
Alexandre Julliard's avatar
Alexandre Julliard committed
1547

1548
    parent = GetParent (hwnd);
1549
    GetClientRect(parent, &parent_rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
1550

1551 1552 1553
    x = parent_rect.left;
    y = parent_rect.top;

1554
    if (dwStyle & CCS_NORESIZE) {
1555
	uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1556 1557 1558 1559 1560
	cx = 0;
	cy = 0;
    }
    else {
	infoPtr->nWidth = parent_rect.right - parent_rect.left;
1561
	TOOLBAR_CalcToolbar (hwnd);
1562
	InvalidateRect( hwnd, NULL, TRUE );
Alexandre Julliard's avatar
Alexandre Julliard committed
1563 1564
	cy = infoPtr->nHeight;
	cx = infoPtr->nWidth;
1565 1566 1567 1568 1569 1570

	if (dwStyle & CCS_NOMOVEY) {
		GetWindowRect(hwnd, &window_rect);
		ScreenToClient(parent, (LPPOINT)&window_rect.left);
		y = window_rect.top;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1571
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1572

1573
    if (dwStyle & CCS_NOPARENTALIGN)
Alexandre Julliard's avatar
Alexandre Julliard committed
1574
	uPosFlags |= SWP_NOMOVE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1575

1576
    if (!(dwStyle & CCS_NODIVIDER))
1577
	cy += GetSystemMetrics(SM_CYEDGE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1578

1579 1580 1581 1582 1583 1584 1585
    if (dwStyle & WS_BORDER)
    {
        x = y = 1;
        cy += GetSystemMetrics(SM_CYEDGE);
        cx += GetSystemMetrics(SM_CYEDGE);
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
1586
    infoPtr->bAutoSize = TRUE;
1587 1588 1589 1590 1591
    SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
                        cx, cy, uPosFlags);
    /* The following line makes sure that the infoPtr->bAutoSize is turned off after
     * the setwindowpos calls */
    infoPtr->bAutoSize = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1592 1593 1594

    return 0;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1595 1596 1597


static LRESULT
1598
TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1599
{
1600
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1601 1602 1603 1604 1605 1606

    return infoPtr->nNumButtons;
}


static LRESULT
1607
TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1608
{
1609
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1610

Alexandre Julliard's avatar
Alexandre Julliard committed
1611
    if (infoPtr == NULL) {
1612 1613
	ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
	ERR("infoPtr == NULL!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
1614 1615 1616
	return 0;
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
1617 1618 1619 1620 1621 1622 1623
    infoPtr->dwStructSize = (DWORD)wParam;

    return 0;
}


static LRESULT
1624
TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1625
{
1626
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1627
    TBUTTON_INFO *btnPtr;
1628
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
1629

1630
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1631 1632 1633 1634 1635 1636
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    btnPtr->iBitmap = LOWORD(lParam);

1637
    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1638 1639 1640 1641 1642 1643

    return TRUE;
}


static LRESULT
1644
TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1645
{
1646
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1647
    TBUTTON_INFO *btnPtr;
1648 1649
    INT nIndex;
    INT nOldIndex = -1;
1650
    BOOL bChecked = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1651

1652
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1653 1654 1655 1656
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
Alexandre Julliard's avatar
Alexandre Julliard committed
1657 1658 1659 1660

    if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
	return FALSE;

1661 1662
    bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1663 1664
    if (LOWORD(lParam) == FALSE)
	btnPtr->fsState &= ~TBSTATE_CHECKED;
Alexandre Julliard's avatar
Alexandre Julliard committed
1665 1666 1667 1668 1669 1670 1671 1672 1673
    else {
	if (btnPtr->fsStyle & TBSTYLE_GROUP) {
	    nOldIndex = 
		TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
	    if (nOldIndex == nIndex)
		return 0;
	    if (nOldIndex != -1)
		infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1674
	btnPtr->fsState |= TBSTATE_CHECKED;
Alexandre Julliard's avatar
Alexandre Julliard committed
1675
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1676

1677 1678 1679
    if( bChecked != LOWORD(lParam) )
    {
	if (nOldIndex != -1)
1680 1681
            InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
1682
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1683

Alexandre Julliard's avatar
Alexandre Julliard committed
1684
    /* FIXME: Send a WM_NOTIFY?? */
Alexandre Julliard's avatar
Alexandre Julliard committed
1685

Alexandre Julliard's avatar
Alexandre Julliard committed
1686 1687 1688 1689 1690
    return TRUE;
}


static LRESULT
1691
TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1692
{
1693
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1694

1695
    return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1696 1697 1698
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1699
static LRESULT
1700
TOOLBAR_Customize (HWND hwnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
1701
{
1702 1703 1704 1705 1706
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    LRESULT ret;
    LPCVOID template;
    HRSRC hRes;
    NMHDR nmhdr;
Alexandre Julliard's avatar
Alexandre Julliard committed
1707

1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736
    /* send TBN_BEGINADJUST notification */
    nmhdr.hwndFrom = hwnd;
    nmhdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
    nmhdr.code     = TBN_BEGINADJUST;

    SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
		  (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);

    if (!(hRes = FindResourceA (COMCTL32_hModule,
                                MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
                                RT_DIALOGA)))
	return FALSE;

    if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
	return FALSE;

    ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
                                   (LPDLGTEMPLATEA)template,
                                   hwnd,
                                   (DLGPROC)TOOLBAR_CustomizeDialogProc,
                                   (LPARAM)infoPtr);

    /* send TBN_ENDADJUST notification */
    nmhdr.code = TBN_ENDADJUST;

    SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
		  (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);

    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1737
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1738 1739 1740


static LRESULT
1741
TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1742
{
1743
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1744
    INT nIndex = (INT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
1745

Alexandre Julliard's avatar
Alexandre Julliard committed
1746
    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
Alexandre Julliard's avatar
Alexandre Julliard committed
1747 1748
	return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1749 1750
    if ((infoPtr->hwndToolTip) && 
	!(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
1751
	TTTOOLINFOA ti;
Alexandre Julliard's avatar
Alexandre Julliard committed
1752

1753 1754
	ZeroMemory (&ti, sizeof(TTTOOLINFOA));
	ti.cbSize   = sizeof (TTTOOLINFOA);
1755
	ti.hwnd     = hwnd;
Alexandre Julliard's avatar
Alexandre Julliard committed
1756 1757
	ti.uId      = infoPtr->buttons[nIndex].idCommand;

1758
	SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
Alexandre Julliard's avatar
Alexandre Julliard committed
1759 1760
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
1761
    if (infoPtr->nNumButtons == 1) {
1762
	TRACE(" simple delete!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
1763
	COMCTL32_Free (infoPtr->buttons);
Alexandre Julliard's avatar
Alexandre Julliard committed
1764 1765 1766 1767
	infoPtr->buttons = NULL;
	infoPtr->nNumButtons = 0;
    }
    else {
Alexandre Julliard's avatar
Alexandre Julliard committed
1768
	TBUTTON_INFO *oldButtons = infoPtr->buttons;
1769
        TRACE("complex delete! [nIndex=%d]\n", nIndex);
Alexandre Julliard's avatar
Alexandre Julliard committed
1770

Alexandre Julliard's avatar
Alexandre Julliard committed
1771
	infoPtr->nNumButtons--;
Alexandre Julliard's avatar
Alexandre Julliard committed
1772
	infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
Alexandre Julliard's avatar
Alexandre Julliard committed
1773 1774 1775 1776
        if (nIndex > 0) {
            memcpy (&infoPtr->buttons[0], &oldButtons[0],
                    nIndex * sizeof(TBUTTON_INFO));
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
1777

Alexandre Julliard's avatar
Alexandre Julliard committed
1778 1779 1780 1781 1782
        if (nIndex < infoPtr->nNumButtons) {
            memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
                    (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
        }

Alexandre Julliard's avatar
Alexandre Julliard committed
1783
	COMCTL32_Free (oldButtons);
Alexandre Julliard's avatar
Alexandre Julliard committed
1784 1785
    }

1786
    TOOLBAR_CalcToolbar (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1787

1788
    InvalidateRect (hwnd, NULL, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1789 1790 1791 1792 1793 1794

    return TRUE;
}


static LRESULT
1795
TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1796
{
1797
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1798
    TBUTTON_INFO *btnPtr;
1799
    INT nIndex;
1800
    DWORD bState;
Alexandre Julliard's avatar
Alexandre Julliard committed
1801

1802
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1803 1804 1805 1806
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
1807 1808 1809 1810 1811 1812 1813

    bState = btnPtr->fsState & TBSTATE_ENABLED;

    /* update the toolbar button state */
    if(LOWORD(lParam) == FALSE) {
 	btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
    } else {
Alexandre Julliard's avatar
Alexandre Julliard committed
1814
	btnPtr->fsState |= TBSTATE_ENABLED;
1815
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1816

1817
    /* redraw the button only if the state of the button changed */
1818 1819
    if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
        InvalidateRect(hwnd, &btnPtr->rect, TRUE);            
Alexandre Julliard's avatar
Alexandre Julliard committed
1820 1821 1822 1823 1824

    return TRUE;
}


1825 1826 1827 1828 1829 1830 1831
static inline LRESULT
TOOLBAR_GetAnchorHighlight (HWND hwnd)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);

    return infoPtr->bAnchor;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1832 1833 1834


static LRESULT
1835
TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1836
{
1837
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1838
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
1839

1840
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1841
    if (nIndex == -1)
Alexandre Julliard's avatar
Alexandre Julliard committed
1842
	return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
1843 1844 1845 1846 1847

    return infoPtr->buttons[nIndex].iBitmap;
}


Patrik Stridvall's avatar
Patrik Stridvall committed
1848
static inline LRESULT
1849
TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1850
{
1851
    return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1852 1853 1854 1855
}


static LRESULT
1856
TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1857
{
1858
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1859
    LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1860
    INT nIndex = (INT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
1861 1862
    TBUTTON_INFO *btnPtr;

1863 1864 1865 1866 1867
    if (infoPtr == NULL)
	return FALSE;

    if (lpTbb == NULL)
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883

    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    lpTbb->iBitmap   = btnPtr->iBitmap;
    lpTbb->idCommand = btnPtr->idCommand;
    lpTbb->fsState   = btnPtr->fsState;
    lpTbb->fsStyle   = btnPtr->fsStyle;
    lpTbb->dwData    = btnPtr->dwData;
    lpTbb->iString   = btnPtr->iString;

    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1884
static LRESULT
1885
TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1886
{
1887
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1888
    LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
1889
    TBUTTON_INFO *btnPtr;
1890
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
1891

1892 1893 1894 1895
    if (infoPtr == NULL)
	return -1;
    if (lpTbInfo == NULL)
	return -1;
Juergen Schmied's avatar
Juergen Schmied committed
1896
    if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
1897
	return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
1898

1899
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
    if (nIndex == -1)
	return -1;

    btnPtr = &infoPtr->buttons[nIndex];

    if (lpTbInfo->dwMask & TBIF_COMMAND)
	lpTbInfo->idCommand = btnPtr->idCommand;
    if (lpTbInfo->dwMask & TBIF_IMAGE)
	lpTbInfo->iImage = btnPtr->iBitmap;
    if (lpTbInfo->dwMask & TBIF_LPARAM)
	lpTbInfo->lParam = btnPtr->dwData;
    if (lpTbInfo->dwMask & TBIF_SIZE)
	lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
    if (lpTbInfo->dwMask & TBIF_STATE)
	lpTbInfo->fsState = btnPtr->fsState;
    if (lpTbInfo->dwMask & TBIF_STYLE)
	lpTbInfo->fsStyle = btnPtr->fsStyle;
1917 1918 1919 1920 1921 1922 1923 1924
     if (lpTbInfo->dwMask & TBIF_TEXT) {
         if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
         {	
             lstrcpynWtoA (lpTbInfo->pszText,
                           (LPWSTR)infoPtr->strings[btnPtr->iString],
                           lpTbInfo->cchText);
         }
         else lpTbInfo->pszText[0]=0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1925 1926 1927 1928 1929
    }
    return nIndex;
}


1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
static LRESULT
TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
    TBUTTON_INFO *btnPtr;
    INT nIndex;

    if (infoPtr == NULL)
	return -1;
    if (lpTbInfo == NULL)
	return -1;
    if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
	return -1;

    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    if (nIndex == -1)
	return -1;

    btnPtr = &infoPtr->buttons[nIndex];

    if (lpTbInfo->dwMask & TBIF_COMMAND)
	lpTbInfo->idCommand = btnPtr->idCommand;
    if (lpTbInfo->dwMask & TBIF_IMAGE)
	lpTbInfo->iImage = btnPtr->iBitmap;
    if (lpTbInfo->dwMask & TBIF_LPARAM)
	lpTbInfo->lParam = btnPtr->dwData;
    if (lpTbInfo->dwMask & TBIF_SIZE)
	lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
    if (lpTbInfo->dwMask & TBIF_STATE)
	lpTbInfo->fsState = btnPtr->fsState;
    if (lpTbInfo->dwMask & TBIF_STYLE)
	lpTbInfo->fsStyle = btnPtr->fsStyle;
    if (lpTbInfo->dwMask & TBIF_TEXT) {
	if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
	    lstrcpynW (lpTbInfo->pszText,
		       (LPWSTR)infoPtr->strings[btnPtr->iString],
		       lpTbInfo->cchText);
    }

    return nIndex;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1972 1973 1974


static LRESULT
1975
TOOLBAR_GetButtonSize (HWND hwnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
1976
{
1977
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1978 1979 1980 1981

    return MAKELONG((WORD)infoPtr->nButtonWidth,
		    (WORD)infoPtr->nButtonHeight);
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1982 1983 1984


static LRESULT
1985
TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1986
{
1987
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1988
    INT nIndex, nStringIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
1989

1990
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1991 1992 1993 1994 1995
    if (nIndex == -1)
	return -1;

    nStringIndex = infoPtr->buttons[nIndex].iString;

1996
    TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
Alexandre Julliard's avatar
Alexandre Julliard committed
1997 1998 1999 2000

    if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
	return -1;

2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028
    if (lParam == 0)
	return -1;

    lstrcpyWtoA ((LPSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);

    return lstrlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
}


static LRESULT
TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    INT nIndex, nStringIndex;

    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    if (nIndex == -1)
	return -1;

    nStringIndex = infoPtr->buttons[nIndex].iString;

    TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);

    if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
	return -1;

    if (lParam == 0)
	return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
2029

2030
    strcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
Alexandre Julliard's avatar
Alexandre Julliard committed
2031

2032
    return lstrlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
Alexandre Julliard's avatar
Alexandre Julliard committed
2033 2034 2035
}


2036
/* << TOOLBAR_GetColorScheme >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2037 2038 2039


static LRESULT
2040
TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2041
{
2042
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2043

2044
    return (LRESULT)infoPtr->himlDis;
Alexandre Julliard's avatar
Alexandre Julliard committed
2045 2046 2047
}


Patrik Stridvall's avatar
Patrik Stridvall committed
2048
inline static LRESULT
2049
TOOLBAR_GetExtendedStyle (HWND hwnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
2050
{
2051
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2052 2053 2054

    return infoPtr->dwExStyle;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2055 2056 2057


static LRESULT
2058
TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2059
{
2060
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2061

2062
    return (LRESULT)infoPtr->himlHot;
Alexandre Julliard's avatar
Alexandre Julliard committed
2063 2064 2065
}


2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
static LRESULT
TOOLBAR_GetHotItem (HWND hwnd)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);

    if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
	return -1;

    if (infoPtr->nHotItem < 0)
	return -1;

    return (LRESULT)infoPtr->nHotItem;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2079 2080 2081


static LRESULT
2082
TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2083
{
2084
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2085

2086
    return (LRESULT)infoPtr->himlDef;
Alexandre Julliard's avatar
Alexandre Julliard committed
2087 2088 2089
}


2090 2091
/* << TOOLBAR_GetInsertMark >> */
/* << TOOLBAR_GetInsertMarkColor >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2092 2093 2094


static LRESULT
2095
TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2096
{
2097
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2098
    TBUTTON_INFO *btnPtr;
2099 2100
    LPRECT     lpRect;
    INT        nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2101

2102 2103
    if (infoPtr == NULL)
	return FALSE;
2104
    nIndex = (INT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2105 2106 2107
    btnPtr = &infoPtr->buttons[nIndex];
    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
	return FALSE;
2108
    lpRect = (LPRECT)lParam;
2109 2110 2111 2112
    if (lpRect == NULL)
	return FALSE;
    if (btnPtr->fsState & TBSTATE_HIDDEN)
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2113
    
2114 2115
    TOOLBAR_CalcToolbar( hwnd );
    
Alexandre Julliard's avatar
Alexandre Julliard committed
2116 2117 2118 2119 2120 2121 2122 2123 2124
    lpRect->left   = btnPtr->rect.left;
    lpRect->right  = btnPtr->rect.right;
    lpRect->bottom = btnPtr->rect.bottom;
    lpRect->top    = btnPtr->rect.top;

    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2125
static LRESULT
2126
TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2127
{
2128
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2129
    LPSIZE lpSize = (LPSIZE)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2130

Alexandre Julliard's avatar
Alexandre Julliard committed
2131 2132 2133
    if (lpSize == NULL)
	return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
2134 2135
    lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
    lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
Alexandre Julliard's avatar
Alexandre Julliard committed
2136

2137
    TRACE("maximum size %d x %d\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
2138 2139
	   infoPtr->rcBound.right - infoPtr->rcBound.left,
	   infoPtr->rcBound.bottom - infoPtr->rcBound.top);
Alexandre Julliard's avatar
Alexandre Julliard committed
2140 2141 2142 2143 2144

    return TRUE;
}


2145 2146
/* << TOOLBAR_GetObject >> */
/* << TOOLBAR_GetPadding >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2147 2148 2149


static LRESULT
2150
TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2151
{
2152
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2153
    TBUTTON_INFO *btnPtr;
2154 2155
    LPRECT     lpRect;
    INT        nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2156

2157 2158
    if (infoPtr == NULL)
	return FALSE;
2159
    nIndex = (INT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2160 2161 2162
    btnPtr = &infoPtr->buttons[nIndex];
    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
	return FALSE;
2163
    lpRect = (LPRECT)lParam;
2164 2165
    if (lpRect == NULL)
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2166 2167 2168 2169 2170 2171 2172 2173
    
    lpRect->left   = btnPtr->rect.left;
    lpRect->right  = btnPtr->rect.right;
    lpRect->bottom = btnPtr->rect.bottom;
    lpRect->top    = btnPtr->rect.top;

    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2174 2175 2176


static LRESULT
2177
TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2178
{
2179
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2180

2181
    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2182
	return infoPtr->nRows;
Alexandre Julliard's avatar
Alexandre Julliard committed
2183 2184 2185 2186 2187 2188
    else
	return 1;
}


static LRESULT
2189
TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2190
{
2191
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2192
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2193

2194
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2195 2196
    if (nIndex == -1)
	return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
2197 2198 2199 2200 2201 2202

    return infoPtr->buttons[nIndex].fsState;
}


static LRESULT
2203
TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2204
{
2205
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2206
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2207

2208
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2209 2210
    if (nIndex == -1)
	return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
2211 2212 2213 2214 2215

    return infoPtr->buttons[nIndex].fsStyle;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2216
static LRESULT
2217
TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2218
{
2219
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2220 2221 2222 2223 2224 2225

    if (infoPtr == NULL)
	return 0;

    return infoPtr->nMaxTextRows;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2226 2227 2228


static LRESULT
2229
TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2230
{
2231
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2232

2233 2234
    if (infoPtr == NULL)
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
2235 2236 2237 2238
    return infoPtr->hwndToolTip;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2239
static LRESULT
2240
TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2241
{
2242
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2243

2244
    TRACE("%s hwnd=0x%x stub!\n", 
2245
	   infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2246 2247 2248

    return infoPtr->bUnicode;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2249 2250


2251 2252 2253 2254 2255 2256 2257 2258
inline static LRESULT
TOOLBAR_GetVersion (HWND hwnd)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    return infoPtr->iVersion;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2259
static LRESULT
2260
TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2261
{
2262
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2263
    TBUTTON_INFO *btnPtr;
2264
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2265

2266
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2267 2268 2269 2270 2271 2272 2273 2274 2275
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    if (LOWORD(lParam) == FALSE)
	btnPtr->fsState &= ~TBSTATE_HIDDEN;
    else
	btnPtr->fsState |= TBSTATE_HIDDEN;

2276
    TOOLBAR_CalcToolbar (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2277

2278
    InvalidateRect (hwnd, NULL, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
2279 2280 2281 2282 2283

    return TRUE;
}


Patrik Stridvall's avatar
Patrik Stridvall committed
2284
inline static LRESULT
2285
TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2286
{
2287
    return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2288 2289 2290
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2291
static LRESULT
2292
TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2293
{
2294
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2295
    TBUTTON_INFO *btnPtr;
2296
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2297

2298
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2299 2300 2301 2302 2303 2304 2305 2306 2307
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    if (LOWORD(lParam) == FALSE)
	btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
    else
	btnPtr->fsState |= TBSTATE_INDETERMINATE;

2308
    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
2309 2310 2311 2312 2313 2314

    return TRUE;
}


static LRESULT
2315
TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2316
{
2317
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2318
    LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2319
    INT nIndex = (INT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2320 2321
    TBUTTON_INFO *oldButtons;

2322 2323
    if (lpTbb == NULL)
	return FALSE;
2324 2325 2326 2327 2328 2329 2330 2331 2332

    if (nIndex == -1) {
       /* EPP: this seems to be an undocumented call (from my IE4)
	* I assume in that case that:
	* - lpTbb->iString is a string pointer (not a string index in strings[] table
	* - index of insertion is at the end of existing buttons
	* I only see this happen with nIndex == -1, but it could have a special
	* meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
	*/
2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348
       int	len;
       LPSTR	ptr;

       if(lpTbb->iString) {
           len = lstrlenA((char*)lpTbb->iString) + 2;
           ptr = COMCTL32_Alloc(len);
           nIndex = infoPtr->nNumButtons;
           strcpy(ptr, (char*)lpTbb->iString);
           ptr[len - 1] = 0; /* ended by two '\0' */
           lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
           COMCTL32_Free(ptr);
       }
       else {
           ERR("lpTbb->iString is NULL\n");
           return FALSE;
       }
2349 2350 2351

    } else if (nIndex < 0)
       return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2352

2353
    TRACE("inserting button index=%d\n", nIndex);
Alexandre Julliard's avatar
Alexandre Julliard committed
2354 2355
    if (nIndex > infoPtr->nNumButtons) {
	nIndex = infoPtr->nNumButtons;
2356
	TRACE("adjust index=%d\n", nIndex);
Alexandre Julliard's avatar
Alexandre Julliard committed
2357 2358 2359 2360
    }

    oldButtons = infoPtr->buttons;
    infoPtr->nNumButtons++;
Alexandre Julliard's avatar
Alexandre Julliard committed
2361
    infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
Alexandre Julliard's avatar
Alexandre Julliard committed
2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375
    /* pre insert copy */
    if (nIndex > 0) {
	memcpy (&infoPtr->buttons[0], &oldButtons[0],
		nIndex * sizeof(TBUTTON_INFO));
    }

    /* insert new button */
    infoPtr->buttons[nIndex].iBitmap   = lpTbb->iBitmap;
    infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
    infoPtr->buttons[nIndex].fsState   = lpTbb->fsState;
    infoPtr->buttons[nIndex].fsStyle   = lpTbb->fsStyle;
    infoPtr->buttons[nIndex].dwData    = lpTbb->dwData;
    infoPtr->buttons[nIndex].iString   = lpTbb->iString;

Alexandre Julliard's avatar
Alexandre Julliard committed
2376
    if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
2377
	TTTOOLINFOA ti;
Alexandre Julliard's avatar
Alexandre Julliard committed
2378

2379 2380
	ZeroMemory (&ti, sizeof(TTTOOLINFOA));
	ti.cbSize   = sizeof (TTTOOLINFOA);
2381
	ti.hwnd     = hwnd;
Alexandre Julliard's avatar
Alexandre Julliard committed
2382 2383
	ti.uId      = lpTbb->idCommand;
	ti.hinst    = 0;
2384
	ti.lpszText = LPSTR_TEXTCALLBACKA;
Alexandre Julliard's avatar
Alexandre Julliard committed
2385

2386
	SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
Alexandre Julliard's avatar
Alexandre Julliard committed
2387 2388 2389
			0, (LPARAM)&ti);
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
2390 2391 2392 2393 2394 2395
    /* post insert copy */
    if (nIndex < infoPtr->nNumButtons - 1) {
	memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
		(infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
2396
    COMCTL32_Free (oldButtons);
Alexandre Julliard's avatar
Alexandre Julliard committed
2397

2398
    TOOLBAR_CalcToolbar (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2399

2400
    InvalidateRect (hwnd, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
2401 2402 2403 2404 2405

    return TRUE;
}


2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471
static LRESULT
TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
    INT nIndex = (INT)wParam;
    TBUTTON_INFO *oldButtons;

    if (lpTbb == NULL)
	return FALSE;
    if (nIndex < 0)
	return FALSE;

    TRACE("inserting button index=%d\n", nIndex);
    if (nIndex > infoPtr->nNumButtons) {
	nIndex = infoPtr->nNumButtons;
	TRACE("adjust index=%d\n", nIndex);
    }

    oldButtons = infoPtr->buttons;
    infoPtr->nNumButtons++;
    infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
    /* pre insert copy */
    if (nIndex > 0) {
	memcpy (&infoPtr->buttons[0], &oldButtons[0],
		nIndex * sizeof(TBUTTON_INFO));
    }

    /* insert new button */
    infoPtr->buttons[nIndex].iBitmap   = lpTbb->iBitmap;
    infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
    infoPtr->buttons[nIndex].fsState   = lpTbb->fsState;
    infoPtr->buttons[nIndex].fsStyle   = lpTbb->fsStyle;
    infoPtr->buttons[nIndex].dwData    = lpTbb->dwData;
    infoPtr->buttons[nIndex].iString   = lpTbb->iString;

    if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
	TTTOOLINFOW ti;

	ZeroMemory (&ti, sizeof(TTTOOLINFOW));
	ti.cbSize   = sizeof (TTTOOLINFOW);
	ti.hwnd     = hwnd;
	ti.uId      = lpTbb->idCommand;
	ti.hinst    = 0;
	ti.lpszText = LPSTR_TEXTCALLBACKW;

	SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
			0, (LPARAM)&ti);
    }

    /* post insert copy */
    if (nIndex < infoPtr->nNumButtons - 1) {
	memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
		(infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
    }

    COMCTL32_Free (oldButtons);

    TOOLBAR_CalcToolbar (hwnd);

    InvalidateRect (hwnd, NULL, FALSE);

    return TRUE;
}


2472
/* << TOOLBAR_InsertMarkHitTest >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2473 2474


Alexandre Julliard's avatar
Alexandre Julliard committed
2475
static LRESULT
2476
TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2477
{
2478
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2479
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2480

2481
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2482 2483 2484 2485 2486 2487 2488 2489
    if (nIndex == -1)
	return FALSE;

    return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
}


static LRESULT
2490
TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2491
{
2492
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2493
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2494

2495
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2496 2497 2498 2499 2500 2501 2502 2503
    if (nIndex == -1)
	return FALSE;

    return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
}


static LRESULT
2504
TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2505
{
2506
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2507
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2508

2509
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2510 2511 2512 2513 2514 2515 2516 2517
    if (nIndex == -1)
	return FALSE;

    return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
}


static LRESULT
2518
TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2519
{
2520
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2521
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2522

2523
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2524 2525 2526 2527 2528 2529 2530 2531
    if (nIndex == -1)
	return FALSE;

    return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
}


static LRESULT
2532
TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2533
{
2534
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2535
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2536

2537
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2538 2539 2540 2541 2542 2543 2544 2545
    if (nIndex == -1)
	return FALSE;

    return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
}


static LRESULT
2546
TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2547
{
2548
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2549
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2550

2551
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2552 2553 2554 2555 2556 2557 2558
    if (nIndex == -1)
	return FALSE;

    return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
}


2559 2560 2561 2562
/* << TOOLBAR_LoadImages >> */
/* << TOOLBAR_MapAccelerator >> */
/* << TOOLBAR_MarkButton >> */
/* << TOOLBAR_MoveButton >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2563 2564 2565


static LRESULT
2566
TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2567
{
2568
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2569
    TBUTTON_INFO *btnPtr;
2570
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2571

2572
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2573 2574 2575 2576 2577 2578 2579 2580 2581
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    if (LOWORD(lParam) == FALSE)
	btnPtr->fsState &= ~TBSTATE_PRESSED;
    else
	btnPtr->fsState |= TBSTATE_PRESSED;

2582
    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
2583 2584 2585 2586 2587

    return TRUE;
}


2588
/* << TOOLBAR_ReplaceBitmap >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2589 2590 2591


static LRESULT
2592
TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2593
{
Alexandre Julliard's avatar
Alexandre Julliard committed
2594
#if 0
2595
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2596
    LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2597 2598 2599

    if (lpSave == NULL) return 0;

2600
    if ((BOOL)wParam) {
Alexandre Julliard's avatar
Alexandre Julliard committed
2601
	/* save toolbar information */
2602
	FIXME("save to \"%s\" \"%s\"\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
2603 2604 2605 2606 2607 2608 2609
	       lpSave->pszSubKey, lpSave->pszValueName);


    }
    else {
	/* restore toolbar information */

2610
	FIXME("restore from \"%s\" \"%s\"\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
2611 2612 2613 2614
	       lpSave->pszSubKey, lpSave->pszValueName);


    }
Alexandre Julliard's avatar
Alexandre Julliard committed
2615
#endif
Alexandre Julliard's avatar
Alexandre Julliard committed
2616 2617 2618 2619 2620

    return 0;
}


2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
static LRESULT
TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
#if 0
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;

    if (lpSave == NULL)
	return 0;

    if ((BOOL)wParam) {
	/* save toolbar information */
	FIXME("save to \"%s\" \"%s\"\n",
	       lpSave->pszSubKey, lpSave->pszValueName);


    }
    else {
	/* restore toolbar information */

	FIXME("restore from \"%s\" \"%s\"\n",
	       lpSave->pszSubKey, lpSave->pszValueName);


    }
#endif

    return 0;
}


static LRESULT
TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    BOOL bOldAnchor = infoPtr->bAnchor;

    infoPtr->bAnchor = (BOOL)wParam;

    return (LRESULT)bOldAnchor;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2662

Alexandre Julliard's avatar
Alexandre Julliard committed
2663

Alexandre Julliard's avatar
Alexandre Julliard committed
2664
static LRESULT
2665
TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2666
{
2667
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2668 2669 2670 2671

    if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
	return FALSE;

2672 2673 2674 2675 2676
    if (infoPtr->nNumButtons > 0)
        WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
             infoPtr->nNumButtons,
             infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
             LOWORD(lParam), HIWORD(lParam));
2677

2678 2679
    infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
    infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2680

2681 2682 2683 2684 2685 2686
    /* uses image list internals directly */
    if (infoPtr->himlDef) {
        infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
        infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
2687 2688 2689 2690
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2691
static LRESULT
2692
TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2693
{
2694
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2695
    LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2696
    TBUTTON_INFO *btnPtr;
2697
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
2698 2699 2700

    if (lptbbi == NULL)
	return FALSE;
Juergen Schmied's avatar
Juergen Schmied committed
2701
    if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
Alexandre Julliard's avatar
Alexandre Julliard committed
2702 2703
	return FALSE;
    
2704
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    if (lptbbi->dwMask & TBIF_COMMAND)
	btnPtr->idCommand = lptbbi->idCommand;
    if (lptbbi->dwMask & TBIF_IMAGE)
	btnPtr->iBitmap = lptbbi->iImage;
    if (lptbbi->dwMask & TBIF_LPARAM)
	btnPtr->dwData = lptbbi->lParam;
2715 2716
/*    if (lptbbi->dwMask & TBIF_SIZE) */
/*	btnPtr->cx = lptbbi->cx; */
Alexandre Julliard's avatar
Alexandre Julliard committed
2717 2718 2719 2720 2721 2722 2723 2724
    if (lptbbi->dwMask & TBIF_STATE)
	btnPtr->fsState = lptbbi->fsState;
    if (lptbbi->dwMask & TBIF_STYLE)
	btnPtr->fsStyle = lptbbi->fsStyle;

    if (lptbbi->dwMask & TBIF_TEXT) {
	if ((btnPtr->iString >= 0) || 
	    (btnPtr->iString < infoPtr->nNumStrings)) {
2725
	   TRACE("Ooooooch\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
2726
#if 0
2727
	    WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
2728
	    INT len = lstrlenA (lptbbi->pszText);
2729
	    *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
Alexandre Julliard's avatar
Alexandre Julliard committed
2730 2731
#endif

Alexandre Julliard's avatar
Alexandre Julliard committed
2732
	    /* this is the ultimate sollution */
2733
/*	    Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
Alexandre Julliard's avatar
Alexandre Julliard committed
2734 2735 2736 2737 2738 2739 2740
	}
    }

    return TRUE;
}


2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787
static LRESULT
TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
    TBUTTON_INFO *btnPtr;
    INT nIndex;

    if (lptbbi == NULL)
	return FALSE;
    if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
	return FALSE;

    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    if (lptbbi->dwMask & TBIF_COMMAND)
	btnPtr->idCommand = lptbbi->idCommand;
    if (lptbbi->dwMask & TBIF_IMAGE)
	btnPtr->iBitmap = lptbbi->iImage;
    if (lptbbi->dwMask & TBIF_LPARAM)
	btnPtr->dwData = lptbbi->lParam;
/*    if (lptbbi->dwMask & TBIF_SIZE) */
/*	btnPtr->cx = lptbbi->cx; */
    if (lptbbi->dwMask & TBIF_STATE)
	btnPtr->fsState = lptbbi->fsState;
    if (lptbbi->dwMask & TBIF_STYLE)
	btnPtr->fsStyle = lptbbi->fsStyle;

    if (lptbbi->dwMask & TBIF_TEXT) {
	if ((btnPtr->iString >= 0) ||
	    (btnPtr->iString < infoPtr->nNumStrings)) {
#if 0
	    WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
	    INT len = lstrlenW (lptbbi->pszText);
	    *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
#endif

	    /* this is the ultimate sollution */
/*	    Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
	}
    }

    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2788 2789 2790


static LRESULT
2791
TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2792
{
2793
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2794 2795

    if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
2796 2797
    {
        ERR("invalid parameter\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
2798
	return FALSE;
2799
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
2800

2801 2802
    /* Button size can only be set before adding any button to the toolbar
       according to the documentation.  */
2803 2804 2805
    /* this appears to be wrong. WINZIP32.EXE (ver 8) calls this on
       one of its buttons after adding it to the toolbar, and it
       checks that the return value is nonzero - mjm */
2806
    if( infoPtr->nNumButtons != 0 )
2807 2808 2809 2810
    {
        FIXME("Button size set after button in toolbar\n");
        return TRUE;
    }
2811

2812 2813
    infoPtr->nButtonWidth = (INT)LOWORD(lParam);
    infoPtr->nButtonHeight = (INT)HIWORD(lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2814 2815 2816 2817
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2818
static LRESULT
2819
TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2820
{
2821
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2822 2823 2824 2825

    if (infoPtr == NULL)
	return FALSE;

2826 2827
    infoPtr->cxMin = (INT)LOWORD(lParam);
    infoPtr->cxMax = (INT)HIWORD(lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
2828 2829 2830

    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2831 2832 2833


static LRESULT
2834
TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2835
{
2836
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2837
    INT nIndex = (INT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2838 2839 2840 2841

    if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
	return FALSE;

2842
    infoPtr->buttons[nIndex].idCommand = (INT)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2843

Alexandre Julliard's avatar
Alexandre Julliard committed
2844 2845
    if (infoPtr->hwndToolTip) {

2846
	FIXME("change tool tip!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
2847 2848 2849

    }

Alexandre Julliard's avatar
Alexandre Julliard committed
2850 2851 2852 2853
    return TRUE;
}


2854
/* << TOOLBAR_SetColorScheme >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2855 2856 2857


static LRESULT
2858
TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2859
{
2860
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2861 2862
    HIMAGELIST himlTemp;

2863

Alexandre Julliard's avatar
Alexandre Julliard committed
2864 2865 2866 2867 2868 2869 2870 2871 2872
    himlTemp = infoPtr->himlDis;
    infoPtr->himlDis = (HIMAGELIST)lParam;

    /* FIXME: redraw ? */

    return (LRESULT)himlTemp; 
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2873
static LRESULT
2874
TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2875
{
2876
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2877 2878 2879 2880 2881 2882 2883 2884
    DWORD dwTemp;

    dwTemp = infoPtr->dwDTFlags;
    infoPtr->dwDTFlags =
	(infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;

    return (LRESULT)dwTemp;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2885 2886 2887


static LRESULT
2888
TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2889
{
2890
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2891 2892 2893 2894 2895 2896 2897 2898 2899 2900
    DWORD dwTemp;

    dwTemp = infoPtr->dwExStyle;
    infoPtr->dwExStyle = (DWORD)lParam;

    return (LRESULT)dwTemp; 
}


static LRESULT
2901
TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2902
{
2903
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914
    HIMAGELIST himlTemp;

    himlTemp = infoPtr->himlHot;
    infoPtr->himlHot = (HIMAGELIST)lParam;

    /* FIXME: redraw ? */

    return (LRESULT)himlTemp; 
}


2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933
static LRESULT
TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
    INT nOldHotItem = infoPtr->nHotItem;

    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
    {
	infoPtr->nHotItem = (INT)wParam;

	/* FIXME: What else must be done ??? */

    }

    if (nOldHotItem < 0)
	return -1;

    return (LRESULT)nOldHotItem;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2934 2935 2936


static LRESULT
2937
TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2938
{
2939
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2940 2941 2942 2943 2944
    HIMAGELIST himlTemp;

    himlTemp = infoPtr->himlDef;
    infoPtr->himlDef = (HIMAGELIST)lParam;

2945
     infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
Alexandre Julliard's avatar
Alexandre Julliard committed
2946 2947 2948 2949
    /* FIXME: redraw ? */

    return (LRESULT)himlTemp; 
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2950

Alexandre Julliard's avatar
Alexandre Julliard committed
2951 2952

static LRESULT
2953
TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2954
{
2955
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2956

2957
    infoPtr->nIndent = (INT)wParam;
2958 2959 2960

    TOOLBAR_CalcToolbar (hwnd);

2961
    InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
2962 2963 2964 2965 2966

    return TRUE;
}


2967
/* << TOOLBAR_SetInsertMark >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2968 2969 2970


static LRESULT
2971
TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2972
{
2973
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2974 2975 2976 2977 2978 2979 2980 2981 2982

    infoPtr->clrInsertMark = (COLORREF)lParam;

    /* FIXME : redraw ??*/

    return 0;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
2983
static LRESULT
2984
TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
2985
{
2986
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
2987 2988 2989 2990

    if (infoPtr == NULL)
	return FALSE;

2991
    infoPtr->nMaxTextRows = (INT)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
2992 2993 2994 2995 2996

    return TRUE;
}


2997
/* << TOOLBAR_SetPadding >> */
Alexandre Julliard's avatar
Alexandre Julliard committed
2998 2999 3000


static LRESULT
3001
TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3002
{
3003
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3004
    HWND hwndOldNotify;
Alexandre Julliard's avatar
Alexandre Julliard committed
3005

3006 3007
    if (infoPtr == NULL)
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
3008
    hwndOldNotify = infoPtr->hwndNotify;
3009
    infoPtr->hwndNotify = (HWND)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
3010 3011 3012 3013 3014 3015

    return hwndOldNotify;
}


static LRESULT
3016
TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3017
{
3018
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3019
    LPRECT lprc = (LPRECT)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
3020 3021 3022

    if (LOWORD(wParam) > 1) {

3023
	FIXME("multiple rows not supported!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3024 3025

    }
Alexandre Julliard's avatar
Alexandre Julliard committed
3026

Alexandre Julliard's avatar
Alexandre Julliard committed
3027
    /* recalculate toolbar */
3028
    TOOLBAR_CalcToolbar (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3029 3030 3031 3032 3033 3034 3035 3036 3037 3038

    /* return bounding rectangle */
    if (lprc) {
	lprc->left   = infoPtr->rcBound.left;
	lprc->right  = infoPtr->rcBound.right;
	lprc->top    = infoPtr->rcBound.top;
	lprc->bottom = infoPtr->rcBound.bottom;
    }

    /* repaint toolbar */
3039
    InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3040 3041 3042 3043

    return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
3044 3045

static LRESULT
3046
TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3047
{
3048
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3049
    TBUTTON_INFO *btnPtr;
3050
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
3051

3052
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3053 3054 3055 3056 3057 3058
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    btnPtr->fsState = LOWORD(lParam);

3059
    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3060 3061 3062 3063 3064 3065

    return TRUE;
}


static LRESULT
3066
TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3067
{
3068
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3069
    TBUTTON_INFO *btnPtr;
3070
    INT nIndex;
Alexandre Julliard's avatar
Alexandre Julliard committed
3071

3072
    nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3073 3074 3075 3076 3077 3078
    if (nIndex == -1)
	return FALSE;

    btnPtr = &infoPtr->buttons[nIndex];
    btnPtr->fsStyle = LOWORD(lParam);

3079
    InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3080

Alexandre Julliard's avatar
Alexandre Julliard committed
3081
    if (infoPtr->hwndToolTip) {
3082
	FIXME("change tool tip!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3083 3084
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
3085 3086 3087 3088
    return TRUE;
}


Patrik Stridvall's avatar
Patrik Stridvall committed
3089
inline static LRESULT
3090
TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3091
{
3092
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3093

3094 3095
    if (infoPtr == NULL)
	return 0;
3096
    infoPtr->hwndToolTip = (HWND)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
3097 3098 3099 3100
    return 0;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
3101
static LRESULT
3102
TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3103
{
3104
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3105
    BOOL bTemp;
Alexandre Julliard's avatar
Alexandre Julliard committed
3106

3107
    TRACE("%s hwnd=0x%04x stub!\n", 
3108
	   ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3109

Alexandre Julliard's avatar
Alexandre Julliard committed
3110
    bTemp = infoPtr->bUnicode;
3111
    infoPtr->bUnicode = (BOOL)wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
3112 3113

    return bTemp;
Alexandre Julliard's avatar
Alexandre Julliard committed
3114
}
Alexandre Julliard's avatar
Alexandre Julliard committed
3115 3116


3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128
static LRESULT
TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    INT iOldVersion = infoPtr->iVersion;

    infoPtr->iVersion = iVersion;

    return iOldVersion;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
3129
static LRESULT
3130
TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3131
{
3132 3133
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3134
    LOGFONTA logFont;
Alexandre Julliard's avatar
Alexandre Julliard committed
3135 3136

    /* initialize info structure */
Alexandre Julliard's avatar
Alexandre Julliard committed
3137
    infoPtr->nButtonHeight = 22;
3138
    infoPtr->nButtonWidth = 24;
Alexandre Julliard's avatar
Alexandre Julliard committed
3139 3140 3141
    infoPtr->nBitmapHeight = 15;
    infoPtr->nBitmapWidth = 16;

Alexandre Julliard's avatar
Alexandre Julliard committed
3142
    infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
3143
    infoPtr->nRows = 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
3144 3145 3146
    infoPtr->nMaxTextRows = 1;
    infoPtr->cxMin = -1;
    infoPtr->cxMax = -1;
3147 3148
    infoPtr->nNumBitmaps = 0;
    infoPtr->nNumStrings = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
3149

Alexandre Julliard's avatar
Alexandre Julliard committed
3150
    infoPtr->bCaptured = FALSE;
3151
    infoPtr->bUnicode = IsWindowUnicode (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3152 3153
    infoPtr->nButtonDown = -1;
    infoPtr->nOldHit = -1;
3154
    infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
3155 3156
    infoPtr->hwndNotify = GetParent (hwnd);
    infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
3157
    infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
3158 3159
    infoPtr->bAnchor = FALSE; /* no anchor highlighting */
    infoPtr->iVersion = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
3160

3161 3162
    SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
    infoPtr->hFont = CreateFontIndirectA (&logFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
3163

3164
    if (dwStyle & TBSTYLE_TOOLTIPS) {
Alexandre Julliard's avatar
Alexandre Julliard committed
3165
	/* Create tooltip control */
Alexandre Julliard's avatar
Alexandre Julliard committed
3166
	infoPtr->hwndToolTip =
3167 3168 3169
	    CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
			       CW_USEDEFAULT, CW_USEDEFAULT,
			       CW_USEDEFAULT, CW_USEDEFAULT,
3170
			       hwnd, 0, 0, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
3171 3172

	/* Send NM_TOOLTIPSCREATED notification */
Alexandre Julliard's avatar
Alexandre Julliard committed
3173 3174
	if (infoPtr->hwndToolTip) {
	    NMTOOLTIPSCREATED nmttc;
Alexandre Julliard's avatar
Alexandre Julliard committed
3175

3176 3177
	    nmttc.hdr.hwndFrom = hwnd;
	    nmttc.hdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
3178 3179 3180
	    nmttc.hdr.code = NM_TOOLTIPSCREATED;
	    nmttc.hwndToolTips = infoPtr->hwndToolTip;

3181
	    SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
3182
			  (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
Alexandre Julliard's avatar
Alexandre Julliard committed
3183
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
3184 3185
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
3186 3187 3188 3189 3190
    return 0;
}


static LRESULT
3191
TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3192
{
3193
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3194

Alexandre Julliard's avatar
Alexandre Julliard committed
3195
    /* delete tooltip control */
Alexandre Julliard's avatar
Alexandre Julliard committed
3196
    if (infoPtr->hwndToolTip)
3197
	DestroyWindow (infoPtr->hwndToolTip);
Alexandre Julliard's avatar
Alexandre Julliard committed
3198

Alexandre Julliard's avatar
Alexandre Julliard committed
3199 3200
    /* delete button data */
    if (infoPtr->buttons)
Alexandre Julliard's avatar
Alexandre Julliard committed
3201
	COMCTL32_Free (infoPtr->buttons);
Alexandre Julliard's avatar
Alexandre Julliard committed
3202

Alexandre Julliard's avatar
Alexandre Julliard committed
3203 3204
    /* delete strings */
    if (infoPtr->strings) {
3205
	INT i;
Alexandre Julliard's avatar
Alexandre Julliard committed
3206 3207
	for (i = 0; i < infoPtr->nNumStrings; i++)
	    if (infoPtr->strings[i])
Alexandre Julliard's avatar
Alexandre Julliard committed
3208
		COMCTL32_Free (infoPtr->strings[i]);
Alexandre Julliard's avatar
Alexandre Julliard committed
3209

Alexandre Julliard's avatar
Alexandre Julliard committed
3210
	COMCTL32_Free (infoPtr->strings);
Alexandre Julliard's avatar
Alexandre Julliard committed
3211 3212
    }

3213 3214 3215
    /* destroy internal image list */
    if (infoPtr->himlInt)
	ImageList_Destroy (infoPtr->himlInt);
Alexandre Julliard's avatar
Alexandre Julliard committed
3216

Alexandre Julliard's avatar
Alexandre Julliard committed
3217 3218
    /* delete default font */
    if (infoPtr->hFont)
3219
	DeleteObject (infoPtr->hFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
3220

Alexandre Julliard's avatar
Alexandre Julliard committed
3221
    /* free toolbar info data */
Alexandre Julliard's avatar
Alexandre Julliard committed
3222
    COMCTL32_Free (infoPtr);
3223
    SetWindowLongA (hwnd, 0, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
3224 3225 3226 3227 3228

    return 0;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
3229
static LRESULT
3230
TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3231
{
3232
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3233 3234

    if (infoPtr->bTransparent)
3235
	return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3236

3237
    return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3238 3239 3240
}


Eric Pouech's avatar
Eric Pouech committed
3241 3242 3243 3244 3245 3246 3247 3248 3249
static LRESULT
TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);

    return infoPtr->hFont;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
3250
static LRESULT
3251
TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3252
{
3253
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3254
    TBUTTON_INFO *btnPtr;
3255 3256
    POINT pt;
    INT   nHit;
Alexandre Julliard's avatar
Alexandre Julliard committed
3257

3258 3259
    pt.x = (INT)LOWORD(lParam);
    pt.y = (INT)HIWORD(lParam);
3260
    nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
3261 3262 3263 3264 3265

    if (nHit >= 0) {
	btnPtr = &infoPtr->buttons[nHit];
	if (!(btnPtr->fsState & TBSTATE_ENABLED))
	    return 0;
3266
	SetCapture (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3267 3268 3269 3270 3271
	infoPtr->bCaptured = TRUE;
	infoPtr->nButtonDown = nHit;

	btnPtr->fsState |= TBSTATE_PRESSED;

3272
        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3273
    }
3274 3275
    else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
	TOOLBAR_Customize (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3276 3277 3278 3279 3280 3281

    return 0;
}


static LRESULT
3282
TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3283
{
3284
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3285
    TBUTTON_INFO *btnPtr;
3286 3287
    POINT pt;
    INT   nHit;
Alexandre Julliard's avatar
Alexandre Julliard committed
3288

Alexandre Julliard's avatar
Alexandre Julliard committed
3289
    if (infoPtr->hwndToolTip)
3290
	TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
Alexandre Julliard's avatar
Alexandre Julliard committed
3291 3292
			    WM_LBUTTONDOWN, wParam, lParam);

3293 3294
    pt.x = (INT)LOWORD(lParam);
    pt.y = (INT)HIWORD(lParam);
3295
    nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
3296 3297 3298 3299 3300 3301

    if (nHit >= 0) {
	btnPtr = &infoPtr->buttons[nHit];
	if (!(btnPtr->fsState & TBSTATE_ENABLED))
	    return 0;

3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314
	if (btnPtr->fsStyle &  TBSTYLE_DROPDOWN)
	{
	    NMTOOLBARA nmtb;

	    nmtb.hdr.hwndFrom = hwnd;
	    nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
	    nmtb.hdr.code = TBN_DROPDOWN;
	    nmtb.iItem = btnPtr->idCommand;

	    SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
			  (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
	}

3315
	SetCapture (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3316 3317 3318 3319 3320
	infoPtr->bCaptured = TRUE;
	infoPtr->nButtonDown = nHit;
	infoPtr->nOldHit = nHit;

	btnPtr->fsState |= TBSTATE_PRESSED;
3321
        btnPtr->bHot = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
3322

3323
        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3324 3325 3326 3327 3328 3329
    }

    return 0;
}

static LRESULT
3330
TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3331
{
3332
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3333
    TBUTTON_INFO *btnPtr;
3334 3335 3336 3337
    POINT pt;
    INT   nHit;
    INT   nOldIndex = -1;
    BOOL  bSendMessage = TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
3338

Alexandre Julliard's avatar
Alexandre Julliard committed
3339
    if (infoPtr->hwndToolTip)
3340
	TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
Alexandre Julliard's avatar
Alexandre Julliard committed
3341 3342
			    WM_LBUTTONUP, wParam, lParam);

3343 3344
    pt.x = (INT)LOWORD(lParam);
    pt.y = (INT)HIWORD(lParam);
3345
    nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
3346

3347 3348 3349 3350
    /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
    if(infoPtr->nHotItem >= 0)
        infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;

Alexandre Julliard's avatar
Alexandre Julliard committed
3351
    if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
Alexandre Julliard's avatar
Alexandre Julliard committed
3352 3353
	infoPtr->bCaptured = FALSE;
	ReleaseCapture ();
Alexandre Julliard's avatar
Alexandre Julliard committed
3354
	btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
Alexandre Julliard's avatar
Alexandre Julliard committed
3355
	btnPtr->fsState &= ~TBSTATE_PRESSED;
Alexandre Julliard's avatar
Alexandre Julliard committed
3356

Alexandre Julliard's avatar
Alexandre Julliard committed
3357 3358 3359 3360 3361 3362 3363 3364 3365 3366
	if (nHit == infoPtr->nButtonDown) {
	    if (btnPtr->fsStyle & TBSTYLE_CHECK) {
		if (btnPtr->fsStyle & TBSTYLE_GROUP) {
		    nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
			infoPtr->nButtonDown);
		    if (nOldIndex == infoPtr->nButtonDown)
			bSendMessage = FALSE;
		    if ((nOldIndex != infoPtr->nButtonDown) && 
			(nOldIndex != -1))
			infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
Alexandre Julliard's avatar
Alexandre Julliard committed
3367
		    btnPtr->fsState |= TBSTATE_CHECKED;
Alexandre Julliard's avatar
Alexandre Julliard committed
3368 3369 3370 3371 3372 3373 3374
		}
		else {
		    if (btnPtr->fsState & TBSTATE_CHECKED)
			btnPtr->fsState &= ~TBSTATE_CHECKED;
		    else
			btnPtr->fsState |= TBSTATE_CHECKED;
		}
Alexandre Julliard's avatar
Alexandre Julliard committed
3375 3376
	    }
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
3377 3378
	else
	    bSendMessage = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
3379

Alexandre Julliard's avatar
Alexandre Julliard committed
3380
	if (nOldIndex != -1)
3381 3382 3383
            InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE); 
        
        InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3384

3385 3386
	if (bSendMessage) {
	    SendMessageA (GetParent(hwnd), WM_COMMAND,
3387
			  MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3388

3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399
//	    if ((GetWindowLongA(hwnd, GWL_STYLE) & TBSTYLE_DROPDOWN) ||
//		(btnPtr->fsStyle & 0x08/* BTNS_DROPDOWN */)) {
       /* 
        * This appears to be an error. Instead of checking the style of the
        * button in question wine was checking the style of the toolbar 
        * itself. This caused a number of strange behaviors. In my 
        * invistigation i think the whole dropdown thing is still fairly
        * broken. but this helps fix some of the problems.
        */

	if (btnPtr->fsStyle &  TBSTYLE_DROPDOWN) {
3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419
	       NMTOOLBARW	nmtb;

	       nmtb.hdr.hwndFrom = hwnd;
	       nmtb.hdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
	       nmtb.hdr.code     = TBN_DROPDOWN;
	       nmtb.iItem        = nHit;
	       /* nmtb.tbButton not used with TBN_DROPDOWN */
	       if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) {
		  nmtb.pszText      = infoPtr->strings[btnPtr->iString];
		  nmtb.cchText      = lstrlenW(nmtb.pszText);
	       } else {
		  nmtb.pszText      = NULL;
		  nmtb.cchText      = 0;
	       }
	       nmtb.rcButton     = btnPtr->rect;

	       SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
			    (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
	    }
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
3420 3421
	infoPtr->nButtonDown = -1;
	infoPtr->nOldHit = -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
3422 3423 3424 3425 3426
    }

    return 0;
}

3427 3428 3429 3430 3431 3432
static LRESULT
TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    TBUTTON_INFO *hotBtnPtr;

3433 3434 3435
    if (infoPtr->nOldHit < 0)
      return TRUE;

3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451
    hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];

    /* Redraw the button if the last button we were over is the hot button and it
       is enabled */
    if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
    {
	hotBtnPtr->bHot = FALSE;
		    
        InvalidateRect (hwnd, &hotBtnPtr->rect, TRUE);
    }

    infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
    infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */

    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
3452 3453

static LRESULT
3454
TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3455
{
3456
    TBUTTON_INFO *btnPtr, *oldBtnPtr;
3457
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3458 3459
    POINT pt;
    INT   nHit;
3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478
    TRACKMOUSEEVENT trackinfo;

    /* fill in the TRACKMOUSEEVENT struct */
    trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
    trackinfo.dwFlags = TME_QUERY;
    trackinfo.hwndTrack = hwnd;
    trackinfo.dwHoverTime = HOVER_DEFAULT;

    /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
    _TrackMouseEvent(&trackinfo);

    /* Make sure tracking is enabled so we recieve a WM_MOUSELEAVE message */
    if(!(trackinfo.dwFlags & TME_LEAVE)) {
        trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */

        /* call TRACKMOUSEEVENT so we recieve a WM_MOUSELEAVE message */
        /* and can properly deactivate the hot toolbar button */
        _TrackMouseEvent(&trackinfo);
   }
Alexandre Julliard's avatar
Alexandre Julliard committed
3479

Alexandre Julliard's avatar
Alexandre Julliard committed
3480
    if (infoPtr->hwndToolTip)
3481
	TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
Alexandre Julliard's avatar
Alexandre Julliard committed
3482 3483
			    WM_MOUSEMOVE, wParam, lParam);

3484 3485
    pt.x = (INT)LOWORD(lParam);
    pt.y = (INT)HIWORD(lParam);
3486

3487
    nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
3488

3489 3490
    if (infoPtr->nOldHit != nHit)
    {
3491 3492
	/* Remove the effect of an old hot button if the button was enabled and was
	   drawn with the hot button effect */
3493
	if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem && 
3494
		(infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
3495 3496 3497 3498 3499 3500 3501
	{
	    oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
	    oldBtnPtr->bHot = FALSE;
		    
	    InvalidateRect (hwnd, &oldBtnPtr->rect, TRUE);
	}

3502
	/* It's not a separator or in nowhere. It's a hot button. */
3503 3504 3505 3506 3507 3508
	if (nHit >= 0)
	{
	    btnPtr = &infoPtr->buttons[nHit];
	    btnPtr->bHot = TRUE;

	    infoPtr->nHotItem = nHit;
3509 3510 3511

            /* only enabled buttons show hot effect */            
            if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
3512
                InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3513 3514
	}

Alexandre Julliard's avatar
Alexandre Julliard committed
3515 3516 3517 3518
    if (infoPtr->bCaptured) {
	    btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
	    if (infoPtr->nOldHit == infoPtr->nButtonDown) {
		btnPtr->fsState &= ~TBSTATE_PRESSED;
3519
                InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3520 3521 3522
	    }
	    else if (nHit == infoPtr->nButtonDown) {
		btnPtr->fsState |= TBSTATE_PRESSED;
3523
                InvalidateRect(hwnd, &btnPtr->rect, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3524 3525 3526 3527 3528 3529 3530 3531
	    }
	}
	infoPtr->nOldHit = nHit;
    }
    return 0;
}


Patrik Stridvall's avatar
Patrik Stridvall committed
3532
inline static LRESULT
3533
TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3534
{
3535
/*    if (wndPtr->dwStyle & CCS_NODIVIDER) */
3536
	return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
3537 3538
/*    else */
/*	return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
Alexandre Julliard's avatar
Alexandre Julliard committed
3539
}
Alexandre Julliard's avatar
Alexandre Julliard committed
3540 3541


Patrik Stridvall's avatar
Patrik Stridvall committed
3542
inline static LRESULT
3543
TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3544
{
3545
    if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
3546
	((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3547

3548
    return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3549
}
Alexandre Julliard's avatar
Alexandre Julliard committed
3550 3551 3552


static LRESULT
3553
TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3554
{
Alexandre Julliard's avatar
Alexandre Julliard committed
3555
    TOOLBAR_INFO *infoPtr;
Alexandre Julliard's avatar
Alexandre Julliard committed
3556

Alexandre Julliard's avatar
Alexandre Julliard committed
3557
    /* allocate memory for info structure */
Alexandre Julliard's avatar
Alexandre Julliard committed
3558
    infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
3559
    SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
3560

Alexandre Julliard's avatar
Alexandre Julliard committed
3561
    /* paranoid!! */
Alexandre Julliard's avatar
Alexandre Julliard committed
3562
    infoPtr->dwStructSize = sizeof(TBBUTTON);
Alexandre Julliard's avatar
Alexandre Julliard committed
3563

Alexandre Julliard's avatar
Alexandre Julliard committed
3564
    /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
3565 3566 3567 3568
    if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
        HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
	SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
3569

3570
    return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3571 3572 3573 3574
}


static LRESULT
3575
TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3576
{
3577 3578
    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    RECT rcWindow;
3579
    HDC hdc;
Alexandre Julliard's avatar
Alexandre Julliard committed
3580

3581 3582
    if (dwStyle & WS_MINIMIZE)
	return 0; /* Nothing to do */
Alexandre Julliard's avatar
Alexandre Julliard committed
3583

3584
    DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3585

3586
    if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
Alexandre Julliard's avatar
Alexandre Julliard committed
3587 3588
	return 0;

3589 3590 3591 3592
    if (!(dwStyle & CCS_NODIVIDER))
    {
	GetWindowRect (hwnd, &rcWindow);
	OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3593 3594
	if( dwStyle & WS_BORDER )
	    OffsetRect (&rcWindow, 1, 1);
3595 3596
	DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
3597

3598
    ReleaseDC( hwnd, hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
3599 3600 3601 3602 3603

    return 0;
}


Patrik Stridvall's avatar
Patrik Stridvall committed
3604
inline static LRESULT
3605
TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3606
{
3607
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3608 3609
    LPNMHDR lpnmh = (LPNMHDR)lParam;

3610
    TRACE("passing WM_NOTIFY!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3611

Alexandre Julliard's avatar
Alexandre Julliard committed
3612
    if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
3613
	SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,	wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3614 3615

#if 0
3616 3617
	if (lpnmh->code == TTN_GETDISPINFOA) {
	    LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
3618

3619
	    FIXME("retrieving ASCII string\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3620 3621

	}
3622 3623
	else if (lpnmh->code == TTN_GETDISPINFOW) {
	    LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
3624

3625
	    FIXME("retrieving UNICODE string\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3626 3627 3628

	}
#endif
Alexandre Julliard's avatar
Alexandre Julliard committed
3629 3630 3631 3632 3633 3634
    }

    return 0;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
3635
static LRESULT
3636
TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3637
{
3638
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3639 3640
    HDC hdc;
    PAINTSTRUCT ps;
Alexandre Julliard's avatar
Alexandre Julliard committed
3641

3642 3643 3644
    /* fill ps.rcPaint with a default rect */
    memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound)); 

3645
    TOOLBAR_CalcToolbar( hwnd );
3646 3647 3648 3649
    hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
    TOOLBAR_Refresh (hwnd, hdc, &ps);
    if (!wParam) EndPaint (hwnd, &ps);

Alexandre Julliard's avatar
Alexandre Julliard committed
3650 3651 3652 3653 3654
    return 0;
}


static LRESULT
3655
TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3656
{
3657 3658
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3659
    RECT parent_rect;
3660
    RECT window_rect;
3661
    HWND parent;
3662
    INT  x, y;
3663 3664 3665
    INT  cx, cy;
    INT  flags;
    UINT uPosFlags = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
3666

Alexandre Julliard's avatar
Alexandre Julliard committed
3667
    /* Resize deadlock check */
Alexandre Julliard's avatar
Alexandre Julliard committed
3668 3669 3670 3671 3672
    if (infoPtr->bAutoSize) {
	infoPtr->bAutoSize = FALSE;
	return 0;
    }

3673
    flags = (INT) wParam;
Alexandre Julliard's avatar
Alexandre Julliard committed
3674 3675

    /* FIXME for flags =
Alexandre Julliard's avatar
Alexandre Julliard committed
3676
     * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
Alexandre Julliard's avatar
Alexandre Julliard committed
3677 3678
     */

3679
    TRACE("sizing toolbar!\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3680

Alexandre Julliard's avatar
Alexandre Julliard committed
3681
    if (flags == SIZE_RESTORED) {
Alexandre Julliard's avatar
Alexandre Julliard committed
3682
	/* width and height don't apply */
3683
	parent = GetParent (hwnd);
3684
	GetClientRect(parent, &parent_rect);
3685 3686
	x = parent_rect.left;
	y = parent_rect.top;
Alexandre Julliard's avatar
Alexandre Julliard committed
3687

3688
	if (dwStyle & CCS_NORESIZE) {
3689
	    uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3690

3691 3692 3693 3694 3695
	    /*
             * this sets the working width of the toolbar, and
             * Calc Toolbar will not adjust it, only the height
             */
	    infoPtr->nWidth = parent_rect.right - parent_rect.left; 
Alexandre Julliard's avatar
Alexandre Julliard committed
3696 3697
	    cy = infoPtr->nHeight;
	    cx = infoPtr->nWidth;
3698
	    TOOLBAR_CalcToolbar (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3699 3700 3701
	    infoPtr->nWidth = cx;
	    infoPtr->nHeight = cy;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
3702 3703
	else {
	    infoPtr->nWidth = parent_rect.right - parent_rect.left;
3704
	    TOOLBAR_CalcToolbar (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3705 3706
	    cy = infoPtr->nHeight;
	    cx = infoPtr->nWidth;
3707 3708 3709 3710 3711 3712

	    if (dwStyle & CCS_NOMOVEY) {
		GetWindowRect(hwnd, &window_rect);
		ScreenToClient(parent, (LPPOINT)&window_rect.left);
		y = window_rect.top;
	    }
Alexandre Julliard's avatar
Alexandre Julliard committed
3713
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
3714

3715
	if (dwStyle & CCS_NOPARENTALIGN) {
Alexandre Julliard's avatar
Alexandre Julliard committed
3716
	    uPosFlags |= SWP_NOMOVE;
Alexandre Julliard's avatar
Alexandre Julliard committed
3717 3718
	    cy = infoPtr->nHeight;
	    cx = infoPtr->nWidth;
Alexandre Julliard's avatar
Alexandre Julliard committed
3719
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
3720

3721
	if (!(dwStyle & CCS_NODIVIDER))
3722
	    cy += GetSystemMetrics(SM_CYEDGE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3723

3724 3725 3726 3727 3728 3729
	if (dwStyle & WS_BORDER)
	{
	    x = y = 1;
	    cy += GetSystemMetrics(SM_CYEDGE);
	    cx += GetSystemMetrics(SM_CYEDGE);
	}
3730

3731 3732 3733
	SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
			cx, cy, uPosFlags | SWP_NOZORDER);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
3734 3735
    return 0;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
3736 3737


Alexandre Julliard's avatar
Alexandre Julliard committed
3738
static LRESULT
3739
TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
Alexandre Julliard's avatar
Alexandre Julliard committed
3740
{
3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752
    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);

    if (nType == GWL_STYLE) {
	if (lpStyle->styleNew & TBSTYLE_LIST) {
	    infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
	}
	else {
	    infoPtr->dwDTFlags = DT_CENTER;
	}
    }

    TOOLBAR_AutoSize (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3753

3754
    InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
3755

Alexandre Julliard's avatar
Alexandre Julliard committed
3756 3757
    return 0;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
3758 3759 3760



3761
static LRESULT WINAPI
3762
ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
3763
{
3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778

    switch (uMsg)
    {
       case WM_DESTROY:
           return TOOLBAR_Destroy (hwnd, wParam, lParam);

       case WM_NCCREATE:
           return TOOLBAR_NCCreate (hwnd, wParam, lParam);
    }

    if (!TOOLBAR_GetInfoPtr (hwnd))
    {
       return DefWindowProcA (hwnd, uMsg, wParam, lParam);
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
3779 3780 3781
    switch (uMsg)
    {
	case TB_ADDBITMAP:
3782
	    return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3783

3784
	case TB_ADDBUTTONSA:
3785
	    return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3786

3787 3788
	case TB_ADDBUTTONSW:
	    return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3789

3790
	case TB_ADDSTRINGA:
3791
	    return TOOLBAR_AddStringA (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3792

3793
	case TB_ADDSTRINGW:
3794
	    return TOOLBAR_AddStringW (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3795 3796

	case TB_AUTOSIZE:
3797
	    return TOOLBAR_AutoSize (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3798 3799

	case TB_BUTTONCOUNT:
3800
	    return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3801 3802

	case TB_BUTTONSTRUCTSIZE:
3803
	    return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3804 3805

	case TB_CHANGEBITMAP:
3806
	    return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3807

Alexandre Julliard's avatar
Alexandre Julliard committed
3808
	case TB_CHECKBUTTON:
3809
	    return TOOLBAR_CheckButton (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3810 3811

	case TB_COMMANDTOINDEX:
3812
	    return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3813

Alexandre Julliard's avatar
Alexandre Julliard committed
3814
	case TB_CUSTOMIZE:
3815
	    return TOOLBAR_Customize (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3816 3817

	case TB_DELETEBUTTON:
3818
	    return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3819 3820

	case TB_ENABLEBUTTON:
3821
	    return TOOLBAR_EnableButton (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3822

3823 3824
	case TB_GETANCHORHIGHLIGHT:
	    return TOOLBAR_GetAnchorHighlight (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3825 3826

	case TB_GETBITMAP:
3827
	    return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3828

Alexandre Julliard's avatar
Alexandre Julliard committed
3829
	case TB_GETBITMAPFLAGS:
3830
	    return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3831 3832

	case TB_GETBUTTON:
3833
	    return TOOLBAR_GetButton (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3834

3835
	case TB_GETBUTTONINFOA:
3836
	    return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3837

3838 3839
	case TB_GETBUTTONINFOW:
	    return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3840 3841

	case TB_GETBUTTONSIZE:
3842
	    return TOOLBAR_GetButtonSize (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3843

3844
	case TB_GETBUTTONTEXTA:
3845
	    return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3846

3847 3848 3849
	case TB_GETBUTTONTEXTW:
	    return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);

3850
/*	case TB_GETCOLORSCHEME:			*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
3851 3852

	case TB_GETDISABLEDIMAGELIST:
3853
	    return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3854

Alexandre Julliard's avatar
Alexandre Julliard committed
3855
	case TB_GETEXTENDEDSTYLE:
3856
	    return TOOLBAR_GetExtendedStyle (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3857 3858

	case TB_GETHOTIMAGELIST:
3859
	    return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3860

3861 3862
	case TB_GETHOTITEM:
	    return TOOLBAR_GetHotItem (hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
3863 3864

	case TB_GETIMAGELIST:
3865
	    return TOOLBAR_GetImageList (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3866

3867 3868
/*	case TB_GETINSERTMARK:			*/ /* 4.71 */
/*	case TB_GETINSERTMARKCOLOR:		*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
3869 3870

	case TB_GETITEMRECT:
3871
	    return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3872

Alexandre Julliard's avatar
Alexandre Julliard committed
3873
	case TB_GETMAXSIZE:
3874
	    return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3875

3876 3877
/*	case TB_GETOBJECT:			*/ /* 4.71 */
/*	case TB_GETPADDING:			*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
3878 3879

	case TB_GETRECT:
3880
	    return TOOLBAR_GetRect (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3881 3882

	case TB_GETROWS:
3883
	    return TOOLBAR_GetRows (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3884 3885

	case TB_GETSTATE:
3886
	    return TOOLBAR_GetState (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3887 3888

	case TB_GETSTYLE:
3889
	    return TOOLBAR_GetStyle (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3890

Alexandre Julliard's avatar
Alexandre Julliard committed
3891
	case TB_GETTEXTROWS:
3892
	    return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3893 3894

	case TB_GETTOOLTIPS:
3895
	    return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3896

Alexandre Julliard's avatar
Alexandre Julliard committed
3897
	case TB_GETUNICODEFORMAT:
3898
	    return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3899

3900 3901 3902
	case CCM_GETVERSION:
	    return TOOLBAR_GetVersion (hwnd);

Alexandre Julliard's avatar
Alexandre Julliard committed
3903
	case TB_HIDEBUTTON:
3904
	    return TOOLBAR_HideButton (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3905 3906

	case TB_HITTEST:
3907
	    return TOOLBAR_HitTest (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3908

Alexandre Julliard's avatar
Alexandre Julliard committed
3909
	case TB_INDETERMINATE:
3910
	    return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3911

3912
	case TB_INSERTBUTTONA:
3913
	    return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3914

3915 3916 3917
	case TB_INSERTBUTTONW:
	    return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);

3918
/*	case TB_INSERTMARKHITTEST:		*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
3919 3920

	case TB_ISBUTTONCHECKED:
3921
	    return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3922 3923

	case TB_ISBUTTONENABLED:
3924
	    return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3925 3926

	case TB_ISBUTTONHIDDEN:
3927
	    return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3928 3929

	case TB_ISBUTTONHIGHLIGHTED:
3930
	    return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3931 3932

	case TB_ISBUTTONINDETERMINATE:
3933
	    return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3934 3935

	case TB_ISBUTTONPRESSED:
3936
	    return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3937

3938 3939 3940 3941
	case TB_LOADIMAGES:			   /* 4.70 */
	    FIXME("missing standard imagelists\n");
	    return 0;

3942 3943
/*	case TB_MAPACCELERATORA:		*/ /* 4.71 */
/*	case TB_MAPACCELERATORW:		*/ /* 4.71 */
3944 3945
/*	case TB_MARKBUTTON:			*/ /* 4.71 */
/*	case TB_MOVEBUTTON:			*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
3946 3947

	case TB_PRESSBUTTON:
3948
	    return TOOLBAR_PressButton (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3949

3950
/*	case TB_REPLACEBITMAP: */
Alexandre Julliard's avatar
Alexandre Julliard committed
3951

3952
	case TB_SAVERESTOREA:
3953
	    return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3954

3955 3956 3957 3958 3959
	case TB_SAVERESTOREW:
	    return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);

	case TB_SETANCHORHIGHLIGHT:
	    return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3960 3961

	case TB_SETBITMAPSIZE:
3962
	    return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3963

3964
	case TB_SETBUTTONINFOA:
3965
	    return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3966

3967 3968
	case TB_SETBUTTONINFOW:
	    return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3969 3970

	case TB_SETBUTTONSIZE:
3971
	    return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3972

Alexandre Julliard's avatar
Alexandre Julliard committed
3973
	case TB_SETBUTTONWIDTH:
3974
	    return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3975 3976

	case TB_SETCMDID:
3977
	    return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3978

3979
/*	case TB_SETCOLORSCHEME:			*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
3980 3981

	case TB_SETDISABLEDIMAGELIST:
3982
	    return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3983

Alexandre Julliard's avatar
Alexandre Julliard committed
3984
	case TB_SETDRAWTEXTFLAGS:
3985
	    return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3986 3987

	case TB_SETEXTENDEDSTYLE:
3988
	    return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3989 3990

	case TB_SETHOTIMAGELIST:
3991
	    return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3992

3993 3994
	case TB_SETHOTITEM:
	    return TOOLBAR_SetHotItem (hwnd, wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3995 3996

	case TB_SETIMAGELIST:
3997
	    return TOOLBAR_SetImageList (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
3998 3999

	case TB_SETINDENT:
4000
	    return TOOLBAR_SetIndent (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4001

4002
/*	case TB_SETINSERTMARK:			*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
4003 4004

	case TB_SETINSERTMARKCOLOR:
4005
	    return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4006

Alexandre Julliard's avatar
Alexandre Julliard committed
4007
	case TB_SETMAXTEXTROWS:
4008
	    return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4009

4010
/*	case TB_SETPADDING:			*/ /* 4.71 */
Alexandre Julliard's avatar
Alexandre Julliard committed
4011 4012

	case TB_SETPARENT:
4013
	    return TOOLBAR_SetParent (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4014 4015

	case TB_SETROWS:
4016
	    return TOOLBAR_SetRows (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4017 4018

	case TB_SETSTATE:
4019
	    return TOOLBAR_SetState (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4020 4021

	case TB_SETSTYLE:
4022
	    return TOOLBAR_SetStyle (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4023

Alexandre Julliard's avatar
Alexandre Julliard committed
4024
	case TB_SETTOOLTIPS:
4025
	    return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4026

Alexandre Julliard's avatar
Alexandre Julliard committed
4027
	case TB_SETUNICODEFORMAT:
4028
	    return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4029

4030 4031 4032
	case CCM_SETVERSION:
	    return TOOLBAR_SetVersion (hwnd, (INT)wParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
4033

4034
/*	case WM_CHAR: */
Alexandre Julliard's avatar
Alexandre Julliard committed
4035

Alexandre Julliard's avatar
Alexandre Julliard committed
4036
	case WM_CREATE:
4037
	    return TOOLBAR_Create (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4038

Alexandre Julliard's avatar
Alexandre Julliard committed
4039
	case WM_ERASEBKGND:
4040
	    return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4041

Eric Pouech's avatar
Eric Pouech committed
4042 4043 4044
	case WM_GETFONT:
		return TOOLBAR_GetFont (hwnd, wParam, lParam);

4045 4046
/*	case WM_KEYDOWN: */
/*	case WM_KILLFOCUS: */
Alexandre Julliard's avatar
Alexandre Julliard committed
4047

Alexandre Julliard's avatar
Alexandre Julliard committed
4048
	case WM_LBUTTONDBLCLK:
4049
	    return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4050 4051

	case WM_LBUTTONDOWN:
4052
	    return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4053 4054

	case WM_LBUTTONUP:
4055
	    return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4056 4057

	case WM_MOUSEMOVE:
4058
	    return TOOLBAR_MouseMove (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4059

4060 4061 4062
	case WM_MOUSELEAVE:
	    return TOOLBAR_MouseLeave (hwnd, wParam, lParam);	

Alexandre Julliard's avatar
Alexandre Julliard committed
4063
	case WM_NCACTIVATE:
4064
	    return TOOLBAR_NCActivate (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4065 4066

	case WM_NCCALCSIZE:
4067
	    return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4068 4069

	case WM_NCPAINT:
4070
	    return TOOLBAR_NCPaint (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4071

Alexandre Julliard's avatar
Alexandre Julliard committed
4072
	case WM_NOTIFY:
4073
	    return TOOLBAR_Notify (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4074

4075
/*	case WM_NOTIFYFORMAT: */
Alexandre Julliard's avatar
Alexandre Julliard committed
4076 4077

	case WM_PAINT:
4078
	    return TOOLBAR_Paint (hwnd, wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4079 4080

	case WM_SIZE:
4081
	    return TOOLBAR_Size (hwnd, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4082 4083

	case WM_STYLECHANGED:
4084
	    return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4085

4086
/*	case WM_SYSCOLORCHANGE: */
Alexandre Julliard's avatar
Alexandre Julliard committed
4087

4088
/*	case WM_WININICHANGE: */
Alexandre Julliard's avatar
Alexandre Julliard committed
4089 4090 4091 4092 4093 4094

	case WM_CHARTOITEM:
	case WM_COMMAND:
	case WM_DRAWITEM:
	case WM_MEASUREITEM:
	case WM_VKEYTOITEM:
4095
	    return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4096 4097 4098

	default:
	    if (uMsg >= WM_USER)
4099
		ERR("unknown msg %04x wp=%08x lp=%08lx\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
4100
		     uMsg, wParam, lParam);
4101
	    return DefWindowProcA (hwnd, uMsg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
4102 4103 4104 4105 4106
    }
    return 0;
}


4107
VOID
Patrik Stridvall's avatar
Patrik Stridvall committed
4108
TOOLBAR_Register (void)
Alexandre Julliard's avatar
Alexandre Julliard committed
4109
{
4110
    WNDCLASSA wndClass;
Alexandre Julliard's avatar
Alexandre Julliard committed
4111

4112
    ZeroMemory (&wndClass, sizeof(WNDCLASSA));
Alexandre Julliard's avatar
Alexandre Julliard committed
4113
    wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS;
4114
    wndClass.lpfnWndProc   = (WNDPROC)ToolbarWindowProc;
Alexandre Julliard's avatar
Alexandre Julliard committed
4115 4116
    wndClass.cbClsExtra    = 0;
    wndClass.cbWndExtra    = sizeof(TOOLBAR_INFO *);
4117 4118 4119
    wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA);
    wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
    wndClass.lpszClassName = TOOLBARCLASSNAMEA;
Alexandre Julliard's avatar
Alexandre Julliard committed
4120
 
4121
    RegisterClassA (&wndClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
4122
}
4123 4124 4125


VOID
Patrik Stridvall's avatar
Patrik Stridvall committed
4126
TOOLBAR_Unregister (void)
4127
{
4128
    UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);
4129 4130
}