status.c 36.1 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * Interface code to StatusWindow widget/control
 *
 * Copyright 1996 Bruce Milner
5
 * Copyright 1998, 1999 Eric Kohl
6
 * Copyright 2002 Dimitrie O. Paun
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21
 *
22 23 24 25 26 27 28 29 30 31
 * NOTE
 * 
 * This code was audited for completeness against the documented features
 * of Comctl32.dll version 6.0 on Sep. 24, 2002, by Dimitrie O. Paun.
 * 
 * Unless otherwise noted, we believe this code to be complete, as per
 * the specification mentioned above.
 * If you discover missing features, or bugs, please note them below.
 * 
 * TODO:
32 33 34 35 36 37 38 39 40
 * 	-- CCS_BOTTOM (default)
 * 	-- CCS_LEFT
 * 	-- CCS_NODEVIDER
 * 	-- CCS_NOMOVEX
 * 	-- CCS_NOMOVEY
 * 	-- CCS_NOPARENTALIGN
 * 	-- CCS_RIGHT
 * 	-- CCS_TOP
 * 	-- CCS_VERT (defaults to RIGHT)
41
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
42

43
#include <stdarg.h>
44
#include <string.h>
45

46
#include "windef.h"
47
#include "winbase.h"
48
#include "wine/unicode.h"
49 50 51
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
52
#include "commctrl.h"
53
#include "comctl32.h"
54 55
#include "uxtheme.h"
#include "tmschema.h"
56
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
57

58
WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
59 60 61

typedef struct
{
62 63
    INT 	x;
    INT 	style;
64 65
    RECT	bound;
    LPWSTR	text;
66
    HICON       hIcon;
67 68 69 70
} STATUSWINDOWPART;

typedef struct
{
71
    HWND              Self;
72
    HWND              Notify;
73
    WORD              numParts;
74 75 76 77 78
    UINT              height;
    BOOL              simple;
    HWND              hwndToolTip;
    HFONT             hFont;
    HFONT             hDefaultFont;
79 80
    COLORREF          clrBk;		/* background color */
    BOOL              bUnicode;		/* unicode flag */
81
    BOOL              NtfUnicode;	/* notify format */
82 83
    STATUSWINDOWPART  part0;		/* simple window */
    STATUSWINDOWPART* parts;
Filip Navara's avatar
Filip Navara committed
84 85 86
    INT               horizontalBorder;
    INT               verticalBorder;
    INT               horizontalGap;
87
} STATUS_INFO;
88

Alexandre Julliard's avatar
Alexandre Julliard committed
89 90
/*
 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
91
 * The second cdrom contains executables drawstat.exe, gettext.exe,
Alexandre Julliard's avatar
Alexandre Julliard committed
92 93 94
 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
 */

Alexandre Julliard's avatar
Alexandre Julliard committed
95 96 97 98
#define HORZ_BORDER 0
#define VERT_BORDER 2
#define HORZ_GAP    2

99
static const WCHAR themeClass[] = { 'S','t','a','t','u','s',0 };
100

101 102
/* prototype */
static void
103
STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
104 105 106 107 108

static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
{
  return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
}
Alexandre Julliard's avatar
Alexandre Julliard committed
109 110

static void
111
STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
Alexandre Julliard's avatar
Alexandre Julliard committed
112
{
113
    HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
114 115
    POINT pt;
    INT i;
Alexandre Julliard's avatar
Alexandre Julliard committed
116

117
    TRACE("draw size grip %d,%d - %d,%d\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    
    if (theme)
    {
        RECT gripperRect;
        SIZE gripperSize;
        gripperRect = *lpRect;
        if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect, 
            TS_DRAW, &gripperSize)))
        {
            gripperRect.left = gripperRect.right - gripperSize.cx;
            gripperRect.top = gripperRect.bottom - gripperSize.cy;
            if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &gripperRect, NULL)))
                return;
        }
    }
133

Alexandre Julliard's avatar
Alexandre Julliard committed
134 135 136
    pt.x = lpRect->right - 1;
    pt.y = lpRect->bottom - 1;

137 138
    hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
    hOldPen = SelectObject( hdc, hPenFace );
139 140
    MoveToEx (hdc, pt.x - 12, pt.y, NULL);
    LineTo (hdc, pt.x, pt.y);
141
    LineTo (hdc, pt.x, pt.y - 13);
Alexandre Julliard's avatar
Alexandre Julliard committed
142 143 144 145

    pt.x--;
    pt.y--;

146 147
    hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
    SelectObject( hdc, hPenShadow );
Alexandre Julliard's avatar
Alexandre Julliard committed
148
    for (i = 1; i < 11; i += 4) {
149
	MoveToEx (hdc, pt.x - i, pt.y, NULL);
150
	LineTo (hdc, pt.x + 1, pt.y - i - 1);
Alexandre Julliard's avatar
Alexandre Julliard committed
151

152 153
	MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
	LineTo (hdc, pt.x + 1, pt.y - i - 2);
Alexandre Julliard's avatar
Alexandre Julliard committed
154
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
155

156 157
    hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
    SelectObject( hdc, hPenHighlight );
Alexandre Julliard's avatar
Alexandre Julliard committed
158
    for (i = 3; i < 13; i += 4) {
159
	MoveToEx (hdc, pt.x - i, pt.y, NULL);
160
	LineTo (hdc, pt.x + 1, pt.y - i - 1);
Alexandre Julliard's avatar
Alexandre Julliard committed
161 162
    }

163 164 165 166
    SelectObject (hdc, hOldPen);
    DeleteObject( hPenFace );
    DeleteObject( hPenShadow );
    DeleteObject( hPenHighlight );
Alexandre Julliard's avatar
Alexandre Julliard committed
167 168 169
}


170
static void
171
STATUSBAR_DrawPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
Alexandre Julliard's avatar
Alexandre Julliard committed
172
{
173 174
    RECT r = part->bound;
    UINT border = BDR_SUNKENOUTER;
175 176
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    int themePart = SP_PANE;
Alexandre Julliard's avatar
Alexandre Julliard committed
177

178
    TRACE("part bound %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom);
179
    if (part->style & SBT_POPOUT)
180
        border = BDR_RAISEDOUTER;
181
    else if (part->style & SBT_NOBORDERS)
182
        border = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
183

184 185 186 187 188 189 190 191 192
    if (theme)
    {
        if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
            && (infoPtr->simple || (itemID == (infoPtr->numParts-1))))
            themePart = SP_GRIPPERPANE;
        DrawThemeBackground(theme, hdc, themePart, 0, &r, NULL);
    }
    else
        DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
193

194 195 196 197 198 199 200 201
    if (part->style & SBT_OWNERDRAW) {
	DRAWITEMSTRUCT dis;

	dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
	dis.itemID = itemID;
	dis.hwndItem = infoPtr->Self;
	dis.hDC = hdc;
	dis.rcItem = r;
Frank Richter's avatar
Frank Richter committed
202
	dis.itemData = (ULONG_PTR)part->text;
203 204 205 206 207 208 209 210 211
	SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
    } else {
	if (part->hIcon) {
	   INT cy = r.bottom - r.top;

	    r.left += 2;
	    DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
	    r.left += cy;
	}
212
        DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
Alexandre Julliard's avatar
Alexandre Julliard committed
213 214 215 216
    }
}


217
static void
218
STATUSBAR_RefreshPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
Alexandre Julliard's avatar
Alexandre Julliard committed
219
{
220 221
    HBRUSH hbrBk;
    HFONT  hOldFont;
222
    HTHEME theme;
Alexandre Julliard's avatar
Alexandre Julliard committed
223

224
    TRACE("item %d\n", itemID);
225
    if (!IsWindowVisible (infoPtr->Self))
Alexandre Julliard's avatar
Alexandre Julliard committed
226 227
        return;

228 229
    if (part->bound.right < part->bound.left) return;

230 231 232 233 234 235
    if ((theme = GetWindowTheme (infoPtr->Self)))
    {
        RECT cr;
        GetClientRect (infoPtr->Self, &cr);
        DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
236
    else
237 238 239 240 241 242 243 244 245
    {
        if (infoPtr->clrBk != CLR_DEFAULT)
                hbrBk = CreateSolidBrush (infoPtr->clrBk);
        else
                hbrBk = GetSysColorBrush (COLOR_3DFACE);
        FillRect(hdc, &part->bound, hbrBk);
        if (infoPtr->clrBk != CLR_DEFAULT)
                DeleteObject (hbrBk);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
246

247
    hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
248

249
	STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
Alexandre Julliard's avatar
Alexandre Julliard committed
250

251
    SelectObject (hdc, hOldFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
252

253 254
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
        RECT rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
255

256
	GetClientRect (infoPtr->Self, &rect);
257
	STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
258 259 260 261
    }
}


262
static LRESULT
263
STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
264 265
{
    int      i;
266 267 268
    RECT   rect;
    HBRUSH hbrBk;
    HFONT  hOldFont;
269
    HTHEME theme;
Alexandre Julliard's avatar
Alexandre Julliard committed
270

271
    TRACE("\n");
272 273
    if (!IsWindowVisible(infoPtr->Self))
        return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
274

275
    STATUSBAR_SetPartBounds(infoPtr);
276

277
    GetClientRect (infoPtr->Self, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
278

279 280 281 282
    if ((theme = GetWindowTheme (infoPtr->Self)))
    {
        DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
283
    else
284 285 286 287 288 289 290 291 292
    {
        if (infoPtr->clrBk != CLR_DEFAULT)
            hbrBk = CreateSolidBrush (infoPtr->clrBk);
        else
            hbrBk = GetSysColorBrush (COLOR_3DFACE);
        FillRect(hdc, &rect, hbrBk);
        if (infoPtr->clrBk != CLR_DEFAULT)
            DeleteObject (hbrBk);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
293

294
    hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
295

296
    if (infoPtr->simple) {
297
	STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
298
    } else {
299 300 301
	for (i = 0; i < infoPtr->numParts; i++) {
	    STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
302 303
    }

304
    SelectObject (hdc, hOldFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
305

306
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
307
	    STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
308

309
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
310 311 312 313
}


static void
314
STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
Alexandre Julliard's avatar
Alexandre Julliard committed
315 316
{
    STATUSWINDOWPART *part;
317
    RECT rect, *r;
Alexandre Julliard's avatar
Alexandre Julliard committed
318
    int	i;
Alexandre Julliard's avatar
Alexandre Julliard committed
319 320

    /* get our window size */
321
    GetClientRect (infoPtr->Self, &rect);
322
    TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
Alexandre Julliard's avatar
Alexandre Julliard committed
323

Filip Navara's avatar
Filip Navara committed
324 325
    rect.left += infoPtr->horizontalBorder;
    rect.top += infoPtr->verticalBorder;
Alexandre Julliard's avatar
Alexandre Julliard committed
326

Alexandre Julliard's avatar
Alexandre Julliard committed
327
    /* set bounds for simple rectangle */
328
    infoPtr->part0.bound = rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
329 330

    /* set bounds for non-simple rectangles */
331 332 333
    for (i = 0; i < infoPtr->numParts; i++) {
	part = &infoPtr->parts[i];
	r = &infoPtr->parts[i].bound;
Alexandre Julliard's avatar
Alexandre Julliard committed
334 335 336 337 338
	r->top = rect.top;
	r->bottom = rect.bottom;
	if (i == 0)
	    r->left = 0;
	else
Filip Navara's avatar
Filip Navara committed
339
	    r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
Alexandre Julliard's avatar
Alexandre Julliard committed
340 341 342 343
	if (part->x == -1)
	    r->right = rect.right;
	else
	    r->right = part->x;
Alexandre Julliard's avatar
Alexandre Julliard committed
344

345
	if (infoPtr->hwndToolTip) {
346
	    TTTOOLINFOW ti;
Alexandre Julliard's avatar
Alexandre Julliard committed
347

348 349
	    ti.cbSize = sizeof(TTTOOLINFOW);
	    ti.hwnd = infoPtr->Self;
Alexandre Julliard's avatar
Alexandre Julliard committed
350 351
	    ti.uId = i;
	    ti.rect = *r;
352
	    SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
Alexandre Julliard's avatar
Alexandre Julliard committed
353 354
			    0, (LPARAM)&ti);
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
355 356 357
    }
}

Alexandre Julliard's avatar
Alexandre Julliard committed
358

359
static LRESULT
360
STATUSBAR_Relay2Tip (STATUS_INFO *infoPtr, UINT uMsg,
361
		     WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
362
{
363
    MSG msg;
Alexandre Julliard's avatar
Alexandre Julliard committed
364

365
    msg.hwnd = infoPtr->Self;
Alexandre Julliard's avatar
Alexandre Julliard committed
366 367 368 369
    msg.message = uMsg;
    msg.wParam = wParam;
    msg.lParam = lParam;
    msg.time = GetMessageTime ();
370 371
    msg.pt.x = (short)LOWORD(GetMessagePos ());
    msg.pt.y = (short)HIWORD(GetMessagePos ());
Alexandre Julliard's avatar
Alexandre Julliard committed
372

373
    return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
Alexandre Julliard's avatar
Alexandre Julliard committed
374 375 376
}


377
static BOOL
Filip Navara's avatar
Filip Navara committed
378
STATUSBAR_GetBorders (STATUS_INFO *infoPtr, INT out[])
Alexandre Julliard's avatar
Alexandre Julliard committed
379
{
380
    TRACE("\n");
Filip Navara's avatar
Filip Navara committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
    out[0] = infoPtr->horizontalBorder;
    out[1] = infoPtr->verticalBorder;
    out[2] = infoPtr->horizontalGap;

    return TRUE;
}


static BOOL
STATUSBAR_SetBorders (STATUS_INFO *infoPtr, INT in[])
{
    TRACE("\n");
    infoPtr->horizontalBorder = in[0];
    infoPtr->verticalBorder = in[1];
    infoPtr->horizontalGap = in[2];
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
397 398 399 400

    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
401

402
static HICON
403
STATUSBAR_GetIcon (STATUS_INFO *infoPtr, INT nPart)
Alexandre Julliard's avatar
Alexandre Julliard committed
404
{
405
    TRACE("%d\n", nPart);
406
    /* MSDN says: "simple parts are indexed with -1" */
407
    if ((nPart < -1) || (nPart >= infoPtr->numParts))
408
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
409

Alexandre Julliard's avatar
Alexandre Julliard committed
410
    if (nPart == -1)
411
        return (infoPtr->part0.hIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
412
    else
413
        return (infoPtr->parts[nPart].hIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
414 415
}

Alexandre Julliard's avatar
Alexandre Julliard committed
416

417
static INT
418
STATUSBAR_GetParts (STATUS_INFO *infoPtr, INT num_parts, INT parts[])
Alexandre Julliard's avatar
Alexandre Julliard committed
419
{
420
    INT   i;
Alexandre Julliard's avatar
Alexandre Julliard committed
421

422
    TRACE("(%d)\n", num_parts);
Alexandre Julliard's avatar
Alexandre Julliard committed
423 424
    if (parts) {
	for (i = 0; i < num_parts; i++) {
425
	    parts[i] = infoPtr->parts[i].x;
Alexandre Julliard's avatar
Alexandre Julliard committed
426 427
	}
    }
428
    return infoPtr->numParts;
Alexandre Julliard's avatar
Alexandre Julliard committed
429 430 431
}


432
static BOOL
433
STATUSBAR_GetRect (STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
Alexandre Julliard's avatar
Alexandre Julliard committed
434
{
435
    TRACE("part %d\n", nPart);
436 437
    if(nPart >= infoPtr->numParts || nPart < 0)
      return FALSE;
438 439
    if (infoPtr->simple)
	*rect = infoPtr->part0.bound;
Alexandre Julliard's avatar
Alexandre Julliard committed
440
    else
441
	*rect = infoPtr->parts[nPart].bound;
Alexandre Julliard's avatar
Alexandre Julliard committed
442 443 444
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
445

Alexandre Julliard's avatar
Alexandre Julliard committed
446
static LRESULT
447
STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
Alexandre Julliard's avatar
Alexandre Julliard committed
448 449
{
    STATUSWINDOWPART *part;
Alexandre Julliard's avatar
Alexandre Julliard committed
450
    LRESULT result;
Alexandre Julliard's avatar
Alexandre Julliard committed
451

452
    TRACE("part %d\n", nPart);
453 454

    /* MSDN says: "simple parts use index of 0", so this check is ok. */
455 456
    if (nPart < 0 || nPart >= infoPtr->numParts) return 0;

457 458
    if (infoPtr->simple)
	part = &infoPtr->part0;
Alexandre Julliard's avatar
Alexandre Julliard committed
459
    else
460
	part = &infoPtr->parts[nPart];
Alexandre Julliard's avatar
Alexandre Julliard committed
461

462
    if (part->style & SBT_OWNERDRAW)
463
	result = (LRESULT)part->text;
Alexandre Julliard's avatar
Alexandre Julliard committed
464
    else {
465 466 467
        DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
                                                      NULL, 0, NULL, NULL ) - 1 : 0;
        result = MAKELONG( len, part->style );
468 469
        if (part->text && buf)
            WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
Alexandre Julliard's avatar
Alexandre Julliard committed
470 471 472 473
    }
    return result;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
474

475
static LRESULT
476
STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
477 478 479 480
{
    STATUSWINDOWPART *part;
    LRESULT result;

481
    TRACE("part %d\n", nPart);
482 483
    if (nPart < 0 || nPart >= infoPtr->numParts) return 0;

484 485
    if (infoPtr->simple)
	part = &infoPtr->part0;
486
    else
487
	part = &infoPtr->parts[nPart];
488

489
    if (part->style & SBT_OWNERDRAW)
490 491
	result = (LRESULT)part->text;
    else {
492
	result = part->text ? strlenW (part->text) : 0;
493
	result |= (part->style << 16);
494 495
	if (part->text && buf)
	    strcpyW (buf, part->text);
496 497 498
    }
    return result;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
499 500


Alexandre Julliard's avatar
Alexandre Julliard committed
501
static LRESULT
502
STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
Alexandre Julliard's avatar
Alexandre Julliard committed
503 504
{
    STATUSWINDOWPART *part;
505
    DWORD result;
Alexandre Julliard's avatar
Alexandre Julliard committed
506

507
    TRACE("part %d\n", nPart);
508 509 510 511

    /* MSDN says: "simple parts use index of 0", so this check is ok. */
    if (nPart < 0 || nPart >= infoPtr->numParts) return 0;

512 513
    if (infoPtr->simple)
	part = &infoPtr->part0;
Alexandre Julliard's avatar
Alexandre Julliard committed
514
    else
515
	part = &infoPtr->parts[nPart];
Alexandre Julliard's avatar
Alexandre Julliard committed
516

517
    if ((~part->style & SBT_OWNERDRAW) && part->text)
518
	result = strlenW(part->text);
Alexandre Julliard's avatar
Alexandre Julliard committed
519 520 521 522 523 524 525 526
    else
	result = 0;

    result |= (part->style << 16);
    return result;
}

static LRESULT
527
STATUSBAR_GetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
Alexandre Julliard's avatar
Alexandre Julliard committed
528
{
529
    TRACE("\n");
530 531 532 533 534 535 536
    if (tip) {
        CHAR buf[INFOTIPSIZE];
        buf[0]='\0';

        if (infoPtr->hwndToolTip) {
            TTTOOLINFOA ti;
            ti.cbSize = sizeof(TTTOOLINFOA);
537 538
            ti.hwnd = infoPtr->Self;
            ti.uId = id;
539
            ti.lpszText = buf;
540
            SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
541
        }
542
        lstrcpynA (tip, buf, size);
Alexandre Julliard's avatar
Alexandre Julliard committed
543
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
544
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
545 546
}

Alexandre Julliard's avatar
Alexandre Julliard committed
547

548
static LRESULT
549
STATUSBAR_GetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
550
{
551
    TRACE("\n");
552 553 554
    if (tip) {
        WCHAR buf[INFOTIPSIZE];
        buf[0]=0;
555

556 557 558
	if (infoPtr->hwndToolTip) {
	    TTTOOLINFOW ti;
	    ti.cbSize = sizeof(TTTOOLINFOW);
559 560
	    ti.hwnd = infoPtr->Self;
	    ti.uId = id;
561 562 563
            ti.lpszText = buf;
	    SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
	}
564
	lstrcpynW(tip, buf, size);
565 566 567 568 569 570
    }

    return 0;
}


571
static COLORREF
572
STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
Alexandre Julliard's avatar
Alexandre Julliard committed
573 574 575
{
    COLORREF oldBkColor;

576
    oldBkColor = infoPtr->clrBk;
577 578
    infoPtr->clrBk = color;
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
579

580
    TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
Alexandre Julliard's avatar
Alexandre Julliard committed
581 582 583 584
    return oldBkColor;
}


585
static BOOL
586
STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
Alexandre Julliard's avatar
Alexandre Julliard committed
587
{
588
    if ((nPart < -1) || (nPart >= infoPtr->numParts))
589
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
590

591
    TRACE("setting part %d\n", nPart);
592

593
    /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
Alexandre Julliard's avatar
Alexandre Julliard committed
594
    if (nPart == -1) {
595
	if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
596
	    return TRUE;
597
	infoPtr->part0.hIcon = hIcon;
598
	if (infoPtr->simple)
599
            InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
600
    } else {
601
	if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
602 603
	    return TRUE;

604
	infoPtr->parts[nPart].hIcon = hIcon;
605
	if (!(infoPtr->simple))
606
            InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
607
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
608 609 610
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
611

612
static BOOL
613
STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
Alexandre Julliard's avatar
Alexandre Julliard committed
614 615
{

616 617
    TRACE("(height=%d)\n", height);
    if (IsWindowVisible (infoPtr->Self)) {
618 619
	INT  width, x, y;
	RECT parent_rect;
620
        HTHEME theme;
Alexandre Julliard's avatar
Alexandre Julliard committed
621

622
	GetClientRect (infoPtr->Notify, &parent_rect);
Filip Navara's avatar
Filip Navara committed
623
	infoPtr->height = height + infoPtr->verticalBorder;
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
        
        if ((theme = GetWindowTheme (infoPtr->Self)))
        {
            /* Determine bar height from theme such that the content area is
             * 'height' pixels large */
            HDC hdc = GetDC (infoPtr->Self);
            RECT r;
            memset (&r, 0, sizeof (r));
            r.bottom = height;
            if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
            {
                infoPtr->height = r.bottom - r.top;
            }
            ReleaseDC (infoPtr->Self, hdc);
        }
        
Alexandre Julliard's avatar
Alexandre Julliard committed
640 641
	width = parent_rect.right - parent_rect.left;
	x = parent_rect.left;
642
	y = parent_rect.bottom - infoPtr->height;
643
	MoveWindow (infoPtr->Self, parent_rect.left,
644 645
		    parent_rect.bottom - infoPtr->height,
		    width, infoPtr->height, TRUE);
646
	STATUSBAR_SetPartBounds (infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
647 648 649 650 651 652
    }

    return TRUE;
}


653
static BOOL
654
STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
Alexandre Julliard's avatar
Alexandre Julliard committed
655
{
656
    STATUSWINDOWPART *tmp;
657
    int	i, oldNumParts;
Alexandre Julliard's avatar
Alexandre Julliard committed
658

659
    TRACE("(%d,%p)\n", count, parts);
660

661
    oldNumParts = infoPtr->numParts;
662
    infoPtr->numParts = count;
663 664 665
    if (oldNumParts > infoPtr->numParts) {
	for (i = infoPtr->numParts ; i < oldNumParts; i++) {
	    if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
666
		Free (infoPtr->parts[i].text);
Alexandre Julliard's avatar
Alexandre Julliard committed
667
	}
668
    } else if (oldNumParts < infoPtr->numParts) {
669
	tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
670
	if (!tmp) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
671
	for (i = 0; i < oldNumParts; i++) {
672
	    tmp[i] = infoPtr->parts[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
673
	}
674
	if (infoPtr->parts)
675
	    Free (infoPtr->parts);
676
	infoPtr->parts = tmp;
Alexandre Julliard's avatar
Alexandre Julliard committed
677
    }
678
    if (oldNumParts == infoPtr->numParts) {
679
	for (i=0; i < oldNumParts; i++)
680
	    if (infoPtr->parts[i].x != parts[i])
681 682 683 684
		break;
	if (i==oldNumParts) /* Unchanged? no need to redraw! */
	    return TRUE;
    }
685

686 687
    for (i = 0; i < infoPtr->numParts; i++)
	infoPtr->parts[i].x = parts[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
688

689
    if (infoPtr->hwndToolTip) {
690 691 692 693 694 695
	INT nTipCount, i;
	TTTOOLINFOW ti;

	ZeroMemory (&ti, sizeof(TTTOOLINFOW));
	ti.cbSize = sizeof(TTTOOLINFOW);
	ti.hwnd = infoPtr->Self;
Alexandre Julliard's avatar
Alexandre Julliard committed
696

697
	nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
698
	if (nTipCount < infoPtr->numParts) {
Alexandre Julliard's avatar
Alexandre Julliard committed
699
	    /* add tools */
700
	    for (i = nTipCount; i < infoPtr->numParts; i++) {
701
		TRACE("add tool %d\n", i);
Alexandre Julliard's avatar
Alexandre Julliard committed
702
		ti.uId = i;
703
		SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
Alexandre Julliard's avatar
Alexandre Julliard committed
704 705 706
				0, (LPARAM)&ti);
	    }
	}
707
	else if (nTipCount > infoPtr->numParts) {
Alexandre Julliard's avatar
Alexandre Julliard committed
708
	    /* delete tools */
709
	    for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
710 711 712 713
		TRACE("delete tool %d\n", i);
		ti.uId = i;
		SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
				0, (LPARAM)&ti);
Alexandre Julliard's avatar
Alexandre Julliard committed
714 715 716
	    }
	}
    }
717 718
    STATUSBAR_SetPartBounds (infoPtr);
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
719 720 721 722
    return TRUE;
}


723
static BOOL
724
STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
725
		    LPCWSTR text, BOOL isW)
Alexandre Julliard's avatar
Alexandre Julliard committed
726
{
727
    STATUSWINDOWPART *part=NULL;
728
    BOOL changed = FALSE;
729
    INT  oldStyle;
Alexandre Julliard's avatar
Alexandre Julliard committed
730

731
    if (style & SBT_OWNERDRAW) {
Gerald Pfeifer's avatar
Gerald Pfeifer committed
732
         TRACE("part %d, text %p\n",nPart,text);
733 734
    }
    else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
735

736 737 738 739
    /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
     * window is assumed to be a simple window */

    if (nPart == 0x00ff) {
740
	part = &infoPtr->part0;
741
    } else {
742
	if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
743 744 745
	    part = &infoPtr->parts[nPart];
	}
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
746
    if (!part) return FALSE;
747

748 749
    if (part->style != style)
	changed = TRUE;
750

751
    oldStyle = part->style;
752
    part->style = style;
753
    if (style & SBT_OWNERDRAW) {
754 755 756 757 758 759
        if (!(oldStyle & SBT_OWNERDRAW)) {
            if (part->text)
                Free (part->text);
        } else if (part->text == text)
            return TRUE;
        part->text = (LPWSTR)text;
760 761 762
    } else {
	LPWSTR ntext;

763 764 765
	if (text && !isW) {
	    LPCSTR atxt = (LPCSTR)text;
            DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
766
	    ntext = Alloc( (len + 1)*sizeof(WCHAR) );
767 768 769
	    if (!ntext) return FALSE;
            MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
	} else if (text) {
770
	    ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
771 772 773 774
	    if (!ntext) return FALSE;
	    strcpyW (ntext, text);
	} else ntext = 0;

775 776
	/* check if text is unchanged -> no need to redraw */
	if (text) {
777
	    if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
778
		Free(ntext);
779 780 781
		return TRUE;
	    }
	} else {
782
	    if (!changed && !part->text)
783
		return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
784 785
	}

786
	if (part->text && !(oldStyle & SBT_OWNERDRAW))
787
	    Free (part->text);
788 789
	part->text = ntext;
    }
790
    InvalidateRect(infoPtr->Self, &part->bound, FALSE);
791
    UpdateWindow(infoPtr->Self);
Alexandre Julliard's avatar
Alexandre Julliard committed
792 793

    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
794 795
}

Alexandre Julliard's avatar
Alexandre Julliard committed
796

797
static LRESULT
798
STATUSBAR_SetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR text)
799
{
800
    TRACE("part %d: \"%s\"\n", id, text);
801
    if (infoPtr->hwndToolTip) {
802 803
	TTTOOLINFOA ti;
	ti.cbSize = sizeof(TTTOOLINFOA);
804 805
	ti.hwnd = infoPtr->Self;
	ti.uId = id;
Alexandre Julliard's avatar
Alexandre Julliard committed
806
	ti.hinst = 0;
807
	ti.lpszText = text;
808
	SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
Alexandre Julliard's avatar
Alexandre Julliard committed
809 810 811 812 813 814
    }

    return 0;
}


815
static LRESULT
816
STATUSBAR_SetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR text)
817
{
818
    TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
819
    if (infoPtr->hwndToolTip) {
820 821
	TTTOOLINFOW ti;
	ti.cbSize = sizeof(TTTOOLINFOW);
822 823
	ti.hwnd = infoPtr->Self;
	ti.uId = id;
824
	ti.hinst = 0;
825
	ti.lpszText = text;
826
	SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
827 828 829 830 831 832
    }

    return 0;
}


Patrik Stridvall's avatar
Patrik Stridvall committed
833
inline static LRESULT
834
STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
835
{
836
    BOOL bOld = infoPtr->bUnicode;
837

838 839
    TRACE("(0x%x)\n", bUnicode);
    infoPtr->bUnicode = bUnicode;
840

841
    return bOld;
842
}
Alexandre Julliard's avatar
Alexandre Julliard committed
843 844


845
static BOOL
846
STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
Alexandre Julliard's avatar
Alexandre Julliard committed
847
{
Alexandre Julliard's avatar
Alexandre Julliard committed
848 849
    NMHDR  nmhdr;

850 851
    TRACE("(simple=%d)\n", simple);
    if (infoPtr->simple == simple) /* no need to change */
852 853
	return TRUE;

854
    infoPtr->simple = simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
855 856

    /* send notification */
857
    nmhdr.hwndFrom = infoPtr->Self;
858
    nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
859
    nmhdr.code = SBN_SIMPLEMODECHANGE;
860
    SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
861
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
862 863 864 865 866
    return TRUE;
}


static LRESULT
867
STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
Alexandre Julliard's avatar
Alexandre Julliard committed
868
{
869 870 871 872 873
    int	i;

    TRACE("\n");
    for (i = 0; i < infoPtr->numParts; i++) {
	if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
874
	    Free (infoPtr->parts[i].text);
875 876
    }
    if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
877 878
	Free (infoPtr->part0.text);
    Free (infoPtr->parts);
879 880 881 882 883 884 885 886 887

    /* delete default font */
    if (infoPtr->hDefaultFont)
	DeleteObject (infoPtr->hDefaultFont);

    /* delete tool tip control */
    if (infoPtr->hwndToolTip)
	DestroyWindow (infoPtr->hwndToolTip);

888 889
    CloseThemeData (GetWindowTheme (infoPtr->Self));

890
    SetWindowLongPtrW(infoPtr->Self, 0, 0);
891
    Free (infoPtr);
892 893 894 895 896 897 898
    return 0;
}


static LRESULT
STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
{
899
    STATUS_INFO *infoPtr;
900
    NONCLIENTMETRICSW nclm;
901
    DWORD dwStyle;
902
    RECT rect;
903
    int	i, width, len, textHeight = 0;
904
    HDC	hdc;
Alexandre Julliard's avatar
Alexandre Julliard committed
905

906
    TRACE("\n");
907
    infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
908
    if (!infoPtr) goto create_fail;
909
    SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
910

911
    infoPtr->Self = hwnd;
912
    infoPtr->Notify = lpCreate->hwndParent;
913 914 915 916 917
    infoPtr->numParts = 1;
    infoPtr->parts = 0;
    infoPtr->simple = FALSE;
    infoPtr->clrBk = CLR_DEFAULT;
    infoPtr->hFont = 0;
Filip Navara's avatar
Filip Navara committed
918 919 920
    infoPtr->horizontalBorder = HORZ_BORDER;
    infoPtr->verticalBorder = VERT_BORDER;
    infoPtr->horizontalGap = HORZ_GAP;
921

922
    i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
923
    infoPtr->NtfUnicode = (i == NFR_UNICODE);
Alexandre Julliard's avatar
Alexandre Julliard committed
924

925
    GetClientRect (hwnd, &rect);
926 927
    InvalidateRect (hwnd, &rect, 0);
    UpdateWindow(hwnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
928

929 930 931 932
    ZeroMemory (&nclm, sizeof(nclm));
    nclm.cbSize = sizeof(nclm);
    SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
    infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
933 934

    /* initialize simple case */
935 936 937 938 939
    infoPtr->part0.bound = rect;
    infoPtr->part0.text = 0;
    infoPtr->part0.x = 0;
    infoPtr->part0.style = 0;
    infoPtr->part0.hIcon = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
940 941

    /* initialize first part */
942
    infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
943
    if (!infoPtr->parts) goto create_fail;
944 945 946 947 948
    infoPtr->parts[0].bound = rect;
    infoPtr->parts[0].text = 0;
    infoPtr->parts[0].x = -1;
    infoPtr->parts[0].style = 0;
    infoPtr->parts[0].hIcon = 0;
949 950
    
    OpenThemeData (hwnd, themeClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
951

952
    if (IsWindowUnicode (hwnd)) {
953
	infoPtr->bUnicode = TRUE;
954
	if (lpCreate->lpszName &&
955
	    (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
956
	    infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
957
	    if (!infoPtr->parts[0].text) goto create_fail;
958
	    strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
959 960 961
	}
    }
    else {
962
	if (lpCreate->lpszName &&
963 964
	    (len = strlen((LPCSTR)lpCreate->lpszName))) {
            DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
965
	    infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
966
	    if (!infoPtr->parts[0].text) goto create_fail;
967
            MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
968
                                 infoPtr->parts[0].text, lenW );
969
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
970 971
    }

972
    dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
973 974
    /* native seems to clear WS_BORDER, too */
    dwStyle &= ~WS_BORDER;
975 976

    /* statusbars on managed windows should not have SIZEGRIP style */
977 978
    if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent &&
        GetPropA( lpCreate->hwndParent, "__wine_x11_managed" ))
979 980 981
        dwStyle &= ~SBARS_SIZEGRIP;

    SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
982

983
    if ((hdc = GetDC (hwnd))) {
984
	TEXTMETRICW tm;
985
	HFONT hOldFont;
Alexandre Julliard's avatar
Alexandre Julliard committed
986

987 988 989
	hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
	GetTextMetricsW (hdc, &tm);
	textHeight = tm.tmHeight;
990
	SelectObject (hdc, hOldFont);
991
	ReleaseDC (hwnd, hdc);
Alexandre Julliard's avatar
Alexandre Julliard committed
992
    }
993
    TRACE("    textHeight=%d\n", textHeight);
Alexandre Julliard's avatar
Alexandre Julliard committed
994

995
    if (dwStyle & SBT_TOOLTIPS) {
996
	infoPtr->hwndToolTip =
997
	    CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
998 999
			     CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			     CW_USEDEFAULT, hwnd, 0,
1000
			     (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
1001

1002
	if (infoPtr->hwndToolTip) {
Alexandre Julliard's avatar
Alexandre Julliard committed
1003 1004
	    NMTOOLTIPSCREATED nmttc;

1005
	    nmttc.hdr.hwndFrom = hwnd;
1006
	    nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
1007
	    nmttc.hdr.code = NM_TOOLTIPSCREATED;
1008
	    nmttc.hwndToolTips = infoPtr->hwndToolTip;
Alexandre Julliard's avatar
Alexandre Julliard committed
1009

1010
	    SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
1011
			    (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
1012
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1013 1014
    }

1015
    if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
1016
        HTHEME theme;
1017
        GetClientRect (infoPtr->Notify, &rect);
1018
        width = rect.right - rect.left;
Filip Navara's avatar
Filip Navara committed
1019
        infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
        
        if ((theme = GetWindowTheme (hwnd)))
        {
            /* Determine bar height from theme such that the content area is
             * textHeight pixels large */
            HDC hdc = GetDC (hwnd);
            RECT r;
            memset (&r, 0, sizeof (r));
            r.bottom = textHeight;
            if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
            {
                infoPtr->height = r.bottom - r.top;
            }
            ReleaseDC (hwnd, hdc);
        }
    
1036 1037
        SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
			width, infoPtr->height, SWP_NOZORDER);
1038
        STATUSBAR_SetPartBounds (infoPtr);
1039
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1040 1041

    return 0;
1042

1043 1044 1045 1046
create_fail:
    TRACE("    failed!\n");
    if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
    return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
1047 1048 1049
}


1050 1051
/* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
 * of the first part only (usual behaviour) */
1052
static INT
1053
STATUSBAR_WMGetText (STATUS_INFO *infoPtr, INT size, LPWSTR buf)
Alexandre Julliard's avatar
Alexandre Julliard committed
1054
{
1055
    INT len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1056

1057
    TRACE("\n");
1058
    if (!(infoPtr->parts[0].text))
Alexandre Julliard's avatar
Alexandre Julliard committed
1059
        return 0;
1060 1061 1062 1063 1064
    if (infoPtr->bUnicode)
        len = strlenW (infoPtr->parts[0].text);
    else
        len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;

1065
    if (size > len) {
1066
	if (infoPtr->bUnicode)
1067
	    strcpyW (buf, infoPtr->parts[0].text);
1068
	else
1069
            WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
1070
                                 (LPSTR)buf, len+1, NULL, NULL );
1071
	return len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1072
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1073

1074
    return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
1075 1076 1077
}


1078
static BOOL
1079
STATUSBAR_WMNCHitTest (STATUS_INFO *infoPtr, INT x, INT y)
Alexandre Julliard's avatar
Alexandre Julliard committed
1080
{
1081
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1082 1083
	RECT  rect;
	POINT pt;
Alexandre Julliard's avatar
Alexandre Julliard committed
1084

1085
	GetClientRect (infoPtr->Self, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
1086

1087 1088 1089
	pt.x = x;
	pt.y = y;
	ScreenToClient (infoPtr->Self, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
1090 1091 1092 1093

	rect.left = rect.right - 13;
	rect.top += 2;

1094
	if (PtInRect (&rect, pt))
Alexandre Julliard's avatar
Alexandre Julliard committed
1095 1096 1097
	    return HTBOTTOMRIGHT;
    }

1098
    return HTERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1099 1100 1101 1102
}


static LRESULT
1103
STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
1104
{
1105
    PAINTSTRUCT ps;
Alexandre Julliard's avatar
Alexandre Julliard committed
1106

1107
    TRACE("\n");
1108 1109 1110 1111
    if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
    hdc = BeginPaint (infoPtr->Self, &ps);
    STATUSBAR_Refresh (infoPtr, hdc);
    EndPaint (infoPtr->Self, &ps);
Alexandre Julliard's avatar
Alexandre Julliard committed
1112 1113 1114 1115 1116 1117

    return 0;
}


static LRESULT
1118
STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
Alexandre Julliard's avatar
Alexandre Julliard committed
1119
{
1120
    infoPtr->hFont = font;
1121
    TRACE("%p\n", infoPtr->hFont);
1122 1123
    if (redraw)
        InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1124

Alexandre Julliard's avatar
Alexandre Julliard committed
1125 1126 1127 1128
    return 0;
}


1129
static BOOL
1130
STATUSBAR_WMSetText (STATUS_INFO *infoPtr, LPCSTR text)
Alexandre Julliard's avatar
Alexandre Julliard committed
1131 1132
{
    STATUSWINDOWPART *part;
Alexandre Julliard's avatar
Alexandre Julliard committed
1133
    int len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1134

1135
    TRACE("\n");
1136
    if (infoPtr->numParts == 0)
Alexandre Julliard's avatar
Alexandre Julliard committed
1137
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1138

1139
    part = &infoPtr->parts[0];
Alexandre Julliard's avatar
Alexandre Julliard committed
1140 1141
    /* duplicate string */
    if (part->text)
1142
        Free (part->text);
Alexandre Julliard's avatar
Alexandre Julliard committed
1143
    part->text = 0;
1144
    if (infoPtr->bUnicode) {
1145
	if (text && (len = strlenW((LPCWSTR)text))) {
1146
	    part->text = Alloc ((len+1)*sizeof(WCHAR));
1147 1148
	    if (!part->text) return FALSE;
	    strcpyW (part->text, (LPCWSTR)text);
1149 1150 1151
	}
    }
    else {
1152 1153
	if (text && (len = lstrlenA(text))) {
            DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1154
            part->text = Alloc (lenW*sizeof(WCHAR));
1155 1156
	    if (!part->text) return FALSE;
            MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1157
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1158
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1159

1160
    InvalidateRect(infoPtr->Self, &part->bound, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1161

Alexandre Julliard's avatar
Alexandre Julliard committed
1162 1163 1164
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1165

1166
static BOOL
1167
STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
Alexandre Julliard's avatar
Alexandre Julliard committed
1168
{
1169
    INT  width, x, y;
1170
    RECT parent_rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
1171

Alexandre Julliard's avatar
Alexandre Julliard committed
1172
    /* Need to resize width to match parent */
1173 1174
    TRACE("flags %04x\n", flags);

1175
    if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1176
	WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1177 1178
	return FALSE;
    }
1179

1180
    if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1181

1182
    /* width and height don't apply */
1183
    GetClientRect (infoPtr->Notify, &parent_rect);
1184 1185 1186
    width = parent_rect.right - parent_rect.left;
    x = parent_rect.left;
    y = parent_rect.bottom - infoPtr->height;
1187
    MoveWindow (infoPtr->Self, parent_rect.left,
1188 1189 1190 1191
		parent_rect.bottom - infoPtr->height,
		width, infoPtr->height, TRUE);
    STATUSBAR_SetPartBounds (infoPtr);
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1192 1193
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1194

1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
/* update theme after a WM_THEMECHANGED message */
static LRESULT theme_changed (STATUS_INFO* infoPtr)
{
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    CloseThemeData (theme);
    OpenThemeData (infoPtr->Self, themeClass);
    return 0;
}


1205
static LRESULT
1206
STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1207 1208
{
    if (cmd == NF_REQUERY) {
1209
	INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1210 1211 1212 1213 1214 1215
	infoPtr->NtfUnicode = (i == NFR_UNICODE);
    }
    return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1216
static LRESULT
1217
STATUSBAR_SendNotify (STATUS_INFO *infoPtr, UINT code)
Alexandre Julliard's avatar
Alexandre Julliard committed
1218
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1219 1220
    NMHDR  nmhdr;

1221
    TRACE("code %04x\n", code);
1222 1223
    nmhdr.hwndFrom = infoPtr->Self;
    nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
1224
    nmhdr.code = code;
1225
    SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
Alexandre Julliard's avatar
Alexandre Julliard committed
1226 1227 1228 1229 1230
    return 0;
}



1231
static LRESULT WINAPI
1232
StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1233
{
1234
    STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1235 1236
    INT nPart = ((INT) wParam) & 0x00ff;
    LRESULT res;
1237

1238
    TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1239 1240
    if (!infoPtr && msg != WM_CREATE)
        return DefWindowProcW (hwnd, msg, wParam, lParam);
1241

Alexandre Julliard's avatar
Alexandre Julliard committed
1242
    switch (msg) {
Alexandre Julliard's avatar
Alexandre Julliard committed
1243
	case SB_GETBORDERS:
Filip Navara's avatar
Filip Navara committed
1244
	    return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1245 1246

	case SB_GETICON:
1247
	    return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1248 1249

	case SB_GETPARTS:
1250
	    return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1251 1252

	case SB_GETRECT:
1253
	    return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1254

1255
	case SB_GETTEXTA:
1256
	    return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1257

1258
	case SB_GETTEXTW:
1259
	    return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1260

1261 1262
	case SB_GETTEXTLENGTHA:
	case SB_GETTEXTLENGTHW:
1263
	    return STATUSBAR_GetTextLength (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1264

1265
	case SB_GETTIPTEXTA:
1266
	    return STATUSBAR_GetTipTextA (infoPtr,  LOWORD(wParam), (LPSTR)lParam,  HIWORD(wParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1267

1268
	case SB_GETTIPTEXTW:
1269
	    return STATUSBAR_GetTipTextW (infoPtr,  LOWORD(wParam), (LPWSTR)lParam,  HIWORD(wParam));
1270 1271

	case SB_GETUNICODEFORMAT:
1272
	    return infoPtr->bUnicode;
Alexandre Julliard's avatar
Alexandre Julliard committed
1273 1274

	case SB_ISSIMPLE:
1275
	    return infoPtr->simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
1276

Filip Navara's avatar
Filip Navara committed
1277 1278 1279
	case SB_SETBORDERS:
	    return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1280
	case SB_SETBKCOLOR:
1281
	    return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1282 1283

	case SB_SETICON:
1284
	    return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1285 1286

	case SB_SETMINHEIGHT:
1287
	    return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1288

1289
	case SB_SETPARTS:
1290
	    return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1291

1292
	case SB_SETTEXTA:
1293
	    return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1294

1295
	case SB_SETTEXTW:
1296
	    return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1297

1298
	case SB_SETTIPTEXTA:
1299
	    return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1300

1301
	case SB_SETTIPTEXTW:
1302
	    return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1303 1304

	case SB_SETUNICODEFORMAT:
1305
	    return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1306 1307

	case SB_SIMPLE:
1308
	    return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1309 1310

	case WM_CREATE:
1311
	    return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1312 1313

	case WM_DESTROY:
1314
	    return STATUSBAR_WMDestroy (infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
1315 1316

	case WM_GETFONT:
1317
	    return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
1318 1319

	case WM_GETTEXT:
1320
            return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1321 1322

	case WM_GETTEXTLENGTH:
1323
	    return STATUSBAR_GetTextLength (infoPtr, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
1324 1325

	case WM_LBUTTONDBLCLK:
1326
            return STATUSBAR_SendNotify (infoPtr, NM_DBLCLK);
Alexandre Julliard's avatar
Alexandre Julliard committed
1327 1328

	case WM_LBUTTONUP:
1329
	    return STATUSBAR_SendNotify (infoPtr, NM_CLICK);
Alexandre Julliard's avatar
Alexandre Julliard committed
1330 1331

	case WM_MOUSEMOVE:
1332
	    return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1333 1334

	case WM_NCHITTEST:
1335 1336
	    res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
                                        (short)HIWORD(lParam));
1337 1338
	    if (res != HTERROR) return res;
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1339 1340

	case WM_NCLBUTTONUP:
1341
	case WM_NCLBUTTONDOWN:
1342
    	    PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1343
	    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1344

1345 1346
	case WM_NOTIFYFORMAT:
	    return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1347

1348
	case WM_PRINTCLIENT:
Alexandre Julliard's avatar
Alexandre Julliard committed
1349
	case WM_PAINT:
1350
	    return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1351 1352

	case WM_RBUTTONDBLCLK:
1353
	    return STATUSBAR_SendNotify (infoPtr, NM_RDBLCLK);
Alexandre Julliard's avatar
Alexandre Julliard committed
1354 1355

	case WM_RBUTTONUP:
1356
	    return STATUSBAR_SendNotify (infoPtr, NM_RCLICK);
Alexandre Julliard's avatar
Alexandre Julliard committed
1357 1358

	case WM_SETFONT:
1359
	    return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1360 1361

	case WM_SETTEXT:
1362 1363
	    return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1364
	case WM_SIZE:
1365 1366
	    if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
            return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1367

1368 1369 1370
        case WM_THEMECHANGED:
            return theme_changed (infoPtr);

Alexandre Julliard's avatar
Alexandre Julliard committed
1371
	default:
1372
	    if ((msg >= WM_USER) && (msg < WM_APP))
1373
		ERR("unknown msg %04x wp=%04x lp=%08lx\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1374
		     msg, wParam, lParam);
1375
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1376 1377 1378 1379
    }
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1380
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1381
 * STATUS_Register [Internal]
Alexandre Julliard's avatar
Alexandre Julliard committed
1382 1383 1384
 *
 * Registers the status window class.
 */
1385

1386
void
1387
STATUS_Register (void)
Alexandre Julliard's avatar
Alexandre Julliard committed
1388
{
1389
    WNDCLASSW wndClass;
Alexandre Julliard's avatar
Alexandre Julliard committed
1390

1391
    ZeroMemory (&wndClass, sizeof(WNDCLASSW));
Alexandre Julliard's avatar
Alexandre Julliard committed
1392
    wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1393
    wndClass.lpfnWndProc   = StatusWindowProc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1394
    wndClass.cbClsExtra    = 0;
1395
    wndClass.cbWndExtra    = sizeof(STATUS_INFO *);
1396
    wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1397
    wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1398
    wndClass.lpszClassName = STATUSCLASSNAMEW;
1399

1400
    RegisterClassW (&wndClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
1401
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1402

1403 1404 1405 1406 1407 1408 1409

/***********************************************************************
 * STATUS_Unregister [Internal]
 *
 * Unregisters the status window class.
 */

1410
void
1411
STATUS_Unregister (void)
1412
{
1413
    UnregisterClassW (STATUSCLASSNAMEW, NULL);
1414
}