status.c 33.8 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
 * TODO:
23 24
 * 	-- CCS_BOTTOM (default)
 * 	-- CCS_LEFT
25
 * 	-- CCS_NODIVIDER
26 27 28 29 30 31
 * 	-- CCS_NOMOVEX
 * 	-- CCS_NOMOVEY
 * 	-- CCS_NOPARENTALIGN
 * 	-- CCS_RIGHT
 * 	-- CCS_TOP
 * 	-- CCS_VERT (defaults to RIGHT)
32
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
33

34
#include <stdarg.h>
35
#include <string.h>
36

37
#include "windef.h"
38
#include "winbase.h"
39
#include "wine/unicode.h"
40 41 42
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
43
#include "commctrl.h"
44
#include "comctl32.h"
45
#include "uxtheme.h"
46
#include "vssym32.h"
47
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
48

49
WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
50 51 52

typedef struct
{
53 54
    INT 	x;
    INT 	style;
55 56
    RECT	bound;
    LPWSTR	text;
57
    HICON       hIcon;
58 59 60 61
} STATUSWINDOWPART;

typedef struct
{
62
    HWND              Self;
63
    HWND              Notify;
64
    WORD              numParts;
65
    UINT              height;
66
    UINT              minHeight;        /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
67 68 69 70
    BOOL              simple;
    HWND              hwndToolTip;
    HFONT             hFont;
    HFONT             hDefaultFont;
71
    COLORREF          clrBk;		/* background color */
72
    BOOL              bUnicode;         /* notify format. TRUE if notifies in Unicode */
73 74
    STATUSWINDOWPART  part0;		/* simple window */
    STATUSWINDOWPART* parts;
Filip Navara's avatar
Filip Navara committed
75 76 77
    INT               horizontalBorder;
    INT               verticalBorder;
    INT               horizontalGap;
78
} STATUS_INFO;
79

Alexandre Julliard's avatar
Alexandre Julliard committed
80 81
/*
 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
82
 * The second cdrom contains executables drawstat.exe, gettext.exe,
Alexandre Julliard's avatar
Alexandre Julliard committed
83 84 85
 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
 */

Alexandre Julliard's avatar
Alexandre Julliard committed
86 87 88 89
#define HORZ_BORDER 0
#define VERT_BORDER 2
#define HORZ_GAP    2

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

92 93
/* prototype */
static void
94
STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
95 96
static LRESULT
STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd);
97 98 99 100 101

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
102

103 104 105 106 107 108
static UINT
STATUSBAR_ComputeHeight(STATUS_INFO *infoPtr)
{
    HTHEME theme;
    UINT height;
    TEXTMETRICW tm;
109
    int margin;
110 111

    COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm);
112
    margin = (tm.tmInternalLeading ? tm.tmInternalLeading : 2);
113
    height = max(tm.tmHeight + margin + 2*GetSystemMetrics(SM_CYBORDER), infoPtr->minHeight) + infoPtr->verticalBorder;
114 115 116 117 118 119 120

    if ((theme = GetWindowTheme(infoPtr->Self)))
    {
        /* Determine bar height from theme such that the content area is
         * textHeight pixels large */
        HDC hdc = GetDC(infoPtr->Self);
        RECT r;
121 122

        SetRect(&r, 0, 0, 0, max(infoPtr->minHeight, tm.tmHeight));
123 124 125 126 127 128 129 130 131 132 133
        if (SUCCEEDED(GetThemeBackgroundExtent(theme, hdc, SP_PANE, 0, &r, &r)))
        {
            height = r.bottom - r.top;
        }
        ReleaseDC(infoPtr->Self, hdc);
    }

    TRACE("    textHeight=%d+%d, final height=%d\n", tm.tmHeight, tm.tmInternalLeading, height);
    return height;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
134
static void
135
STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
Alexandre Julliard's avatar
Alexandre Julliard committed
136
{
137
    RECT rc = *lpRect;
Alexandre Julliard's avatar
Alexandre Julliard committed
138

139 140
    TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect));

141 142 143 144 145 146
    if (theme)
    {
        SIZE gripperSize;
        if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect, 
            TS_DRAW, &gripperSize)))
        {
147 148 149
            rc.left = rc.right - gripperSize.cx;
            rc.top = rc.bottom - gripperSize.cy;
            if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &rc, NULL)))
150 151 152
                return;
        }
    }
153

154 155 156
    rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
    rc.top  = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
    DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
Alexandre Julliard's avatar
Alexandre Julliard committed
157 158 159
}


160
static void
161
STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
Alexandre Julliard's avatar
Alexandre Julliard committed
162
{
163 164
    RECT r = part->bound;
    UINT border = BDR_SUNKENOUTER;
165 166
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    int themePart = SP_PANE;
167
    int x = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
168

169
    TRACE("part bound %s\n", wine_dbgstr_rect(&r));
170
    if (part->style & SBT_POPOUT)
171
        border = BDR_RAISEDOUTER;
172
    else if (part->style & SBT_NOBORDERS)
173
        border = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
174

175 176 177 178 179 180 181 182 183
    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);
184

185 186 187 188 189 190
    if (part->hIcon) {
        INT cy = r.bottom - r.top;
        DrawIconEx (hdc, r.left + 2, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
        x = 2 + cy;
    }

191 192 193 194 195 196 197 198
    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
199
	dis.itemData = (ULONG_PTR)part->text;
200
        SendMessageW (infoPtr->Notify, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
201
    } else {
202
        r.left += x;
203
        DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
Alexandre Julliard's avatar
Alexandre Julliard committed
204 205 206 207
    }
}


208
static void
209
STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
Alexandre Julliard's avatar
Alexandre Julliard committed
210
{
211
    HBRUSH hbrBk;
212
    HTHEME theme;
Alexandre Julliard's avatar
Alexandre Julliard committed
213

214
    TRACE("item %d\n", itemID);
Alexandre Julliard's avatar
Alexandre Julliard committed
215

216 217
    if (part->bound.right < part->bound.left) return;

218 219 220
    if (!RectVisible(hdc, &part->bound))
        return;

221 222 223 224 225 226
    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
227
    else
228 229 230 231 232 233 234 235 236
    {
        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
237

238
    STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
Alexandre Julliard's avatar
Alexandre Julliard committed
239 240 241
}


242
static LRESULT
243
STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
244
{
245 246 247
    RECT   rect;
    HBRUSH hbrBk;
    HFONT  hOldFont;
248
    HTHEME theme;
Alexandre Julliard's avatar
Alexandre Julliard committed
249

250
    TRACE("\n");
251 252
    if (!IsWindowVisible(infoPtr->Self))
        return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
253

254
    STATUSBAR_SetPartBounds(infoPtr);
255

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

258 259 260 261
    if ((theme = GetWindowTheme (infoPtr->Self)))
    {
        DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
262
    else
263 264 265 266 267 268 269 270 271
    {
        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
272

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

275
    if (infoPtr->simple) {
276
	STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
277
    } else {
278 279
        unsigned int i;

280 281 282
	for (i = 0; i < infoPtr->numParts; i++) {
	    STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
283 284
    }

285
    SelectObject (hdc, hOldFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
286

287
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
288
	    STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
289

290
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
291 292 293
}


294
static int
295
STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const POINT *pt)
296
{
297 298
    unsigned int i;

299 300 301 302 303 304 305 306 307 308
    if (infoPtr->simple)
        return 255;

    for (i = 0; i < infoPtr->numParts; i++)
        if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
            return i;
    return -2;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
309
static void
310
STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
Alexandre Julliard's avatar
Alexandre Julliard committed
311 312
{
    STATUSWINDOWPART *part;
313
    RECT rect, *r;
314
    UINT i;
Alexandre Julliard's avatar
Alexandre Julliard committed
315 316

    /* get our window size */
317
    GetClientRect (infoPtr->Self, &rect);
318
    TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect));
Alexandre Julliard's avatar
Alexandre Julliard committed
319

Filip Navara's avatar
Filip Navara committed
320 321
    rect.left += infoPtr->horizontalBorder;
    rect.top += infoPtr->verticalBorder;
Alexandre Julliard's avatar
Alexandre Julliard committed
322

Alexandre Julliard's avatar
Alexandre Julliard committed
323
    /* set bounds for simple rectangle */
324
    infoPtr->part0.bound = rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
325 326

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

341
	if (infoPtr->hwndToolTip) {
342
	    TTTOOLINFOW ti;
Alexandre Julliard's avatar
Alexandre Julliard committed
343

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

Alexandre Julliard's avatar
Alexandre Julliard committed
354

355
static LRESULT
356
STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
357
		     WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
358
{
359
    MSG msg;
Alexandre Julliard's avatar
Alexandre Julliard committed
360

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

369
    return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
Alexandre Julliard's avatar
Alexandre Julliard committed
370 371 372
}


373
static BOOL
374
STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
Alexandre Julliard's avatar
Alexandre Julliard committed
375
{
376
    TRACE("\n");
Filip Navara's avatar
Filip Navara committed
377 378 379 380 381 382 383 384 385
    out[0] = infoPtr->horizontalBorder;
    out[1] = infoPtr->verticalBorder;
    out[2] = infoPtr->horizontalGap;

    return TRUE;
}


static BOOL
386
STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
Filip Navara's avatar
Filip Navara committed
387 388 389 390 391 392
{
    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
393 394 395 396

    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
397

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

Alexandre Julliard's avatar
Alexandre Julliard committed
406
    if (nPart == -1)
407
        return (infoPtr->part0.hIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
408
    else
409
        return (infoPtr->parts[nPart].hIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
410 411
}

Alexandre Julliard's avatar
Alexandre Julliard committed
412

413
static INT
414
STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
Alexandre Julliard's avatar
Alexandre Julliard committed
415
{
416
    INT   i;
Alexandre Julliard's avatar
Alexandre Julliard committed
417

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


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

Alexandre Julliard's avatar
Alexandre Julliard committed
441

Alexandre Julliard's avatar
Alexandre Julliard committed
442
static LRESULT
443
STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
Alexandre Julliard's avatar
Alexandre Julliard committed
444 445
{
    STATUSWINDOWPART *part;
Alexandre Julliard's avatar
Alexandre Julliard committed
446
    LRESULT result;
Alexandre Julliard's avatar
Alexandre Julliard committed
447

448
    TRACE("part %d\n", nPart);
449 450

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

453 454
    if (infoPtr->simple)
	part = &infoPtr->part0;
Alexandre Julliard's avatar
Alexandre Julliard committed
455
    else
456
	part = &infoPtr->parts[nPart];
Alexandre Julliard's avatar
Alexandre Julliard committed
457

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

Alexandre Julliard's avatar
Alexandre Julliard committed
470

471
static LRESULT
472
STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
473 474 475 476
{
    STATUSWINDOWPART *part;
    LRESULT result;

477
    TRACE("part %d\n", nPart);
478 479
    if (nPart < 0 || nPart >= infoPtr->numParts) return 0;

480 481
    if (infoPtr->simple)
	part = &infoPtr->part0;
482
    else
483
	part = &infoPtr->parts[nPart];
484

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


Alexandre Julliard's avatar
Alexandre Julliard committed
497
static LRESULT
498
STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
Alexandre Julliard's avatar
Alexandre Julliard committed
499 500
{
    STATUSWINDOWPART *part;
501
    DWORD result;
Alexandre Julliard's avatar
Alexandre Julliard committed
502

503
    TRACE("part %d\n", nPart);
504 505 506 507

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

508 509
    if (infoPtr->simple)
	part = &infoPtr->part0;
Alexandre Julliard's avatar
Alexandre Julliard committed
510
    else
511
	part = &infoPtr->parts[nPart];
Alexandre Julliard's avatar
Alexandre Julliard committed
512

513
    if ((~part->style & SBT_OWNERDRAW) && part->text)
514
	result = strlenW(part->text);
Alexandre Julliard's avatar
Alexandre Julliard committed
515 516 517 518 519 520 521 522
    else
	result = 0;

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

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

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

Alexandre Julliard's avatar
Alexandre Julliard committed
543

544
static LRESULT
545
STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
546
{
547
    TRACE("\n");
548 549 550
    if (tip) {
        WCHAR buf[INFOTIPSIZE];
        buf[0]=0;
551

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

    return 0;
}


567
static COLORREF
568
STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
Alexandre Julliard's avatar
Alexandre Julliard committed
569 570 571
{
    COLORREF oldBkColor;

572
    oldBkColor = infoPtr->clrBk;
573 574
    infoPtr->clrBk = color;
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
575

576
    TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
Alexandre Julliard's avatar
Alexandre Julliard committed
577 578 579 580
    return oldBkColor;
}


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

587
    TRACE("setting part %d\n", nPart);
588

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

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

Alexandre Julliard's avatar
Alexandre Julliard committed
607

608
static BOOL
609
STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
Alexandre Julliard's avatar
Alexandre Julliard committed
610
{
611 612 613
    DWORD ysize = GetSystemMetrics(SM_CYSIZE);
    if (ysize & 1) ysize--;
    infoPtr->minHeight = max(height, ysize);
614 615
    infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
    /* like native, don't resize the control */
Alexandre Julliard's avatar
Alexandre Julliard committed
616 617 618 619
    return TRUE;
}


620
static BOOL
621
STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
Alexandre Julliard's avatar
Alexandre Julliard committed
622
{
623
    STATUSWINDOWPART *tmp;
624
    INT i, oldNumParts;
Alexandre Julliard's avatar
Alexandre Julliard committed
625

626
    TRACE("(%d,%p)\n", count, parts);
627

628 629
    if(!count) return FALSE;

630
    oldNumParts = infoPtr->numParts;
631
    infoPtr->numParts = count;
632 633
    if (oldNumParts > infoPtr->numParts) {
	for (i = infoPtr->numParts ; i < oldNumParts; i++) {
634
	    if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
635
		Free (infoPtr->parts[i].text);
Alexandre Julliard's avatar
Alexandre Julliard committed
636
	}
637
    } else if (oldNumParts < infoPtr->numParts) {
638
	tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
639
	if (!tmp) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
640
	for (i = 0; i < oldNumParts; i++) {
641
	    tmp[i] = infoPtr->parts[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
642
	}
643
        Free (infoPtr->parts);
644
	infoPtr->parts = tmp;
Alexandre Julliard's avatar
Alexandre Julliard committed
645
    }
646
    if (oldNumParts == infoPtr->numParts) {
647
	for (i=0; i < oldNumParts; i++)
648
	    if (infoPtr->parts[i].x != parts[i])
649 650 651 652
		break;
	if (i==oldNumParts) /* Unchanged? no need to redraw! */
	    return TRUE;
    }
653

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

657
    if (infoPtr->hwndToolTip) {
658
	INT nTipCount;
659
	TTTOOLINFOW ti;
660
	WCHAR wEmpty = 0;
661 662 663 664

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

667
	nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
668
	if (nTipCount < infoPtr->numParts) {
Alexandre Julliard's avatar
Alexandre Julliard committed
669
	    /* add tools */
670
	    for (i = nTipCount; i < infoPtr->numParts; i++) {
671
		TRACE("add tool %d\n", i);
Alexandre Julliard's avatar
Alexandre Julliard committed
672
		ti.uId = i;
673
		SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
Alexandre Julliard's avatar
Alexandre Julliard committed
674 675 676
				0, (LPARAM)&ti);
	    }
	}
677
	else if (nTipCount > infoPtr->numParts) {
Alexandre Julliard's avatar
Alexandre Julliard committed
678
	    /* delete tools */
679
	    for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
680 681 682 683
		TRACE("delete tool %d\n", i);
		ti.uId = i;
		SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
				0, (LPARAM)&ti);
Alexandre Julliard's avatar
Alexandre Julliard committed
684 685 686
	    }
	}
    }
687 688
    STATUSBAR_SetPartBounds (infoPtr);
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
689 690 691 692
    return TRUE;
}


693
static BOOL
694
STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
695
		    LPWSTR text, BOOL isW)
Alexandre Julliard's avatar
Alexandre Julliard committed
696
{
697
    STATUSWINDOWPART *part=NULL;
698
    BOOL changed = FALSE;
699
    INT  oldStyle;
Alexandre Julliard's avatar
Alexandre Julliard committed
700

701
    if (style & SBT_OWNERDRAW) {
Gerald Pfeifer's avatar
Gerald Pfeifer committed
702
         TRACE("part %d, text %p\n",nPart,text);
703 704
    }
    else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
705

706 707 708 709
    /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
     * window is assumed to be a simple window */

    if (nPart == 0x00ff) {
710
	part = &infoPtr->part0;
711
    } else {
712
	if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
713 714 715
	    part = &infoPtr->parts[nPart];
	}
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
716
    if (!part) return FALSE;
717

718 719
    if (part->style != style)
	changed = TRUE;
720

721
    oldStyle = part->style;
722
    part->style = style;
723
    if (style & SBT_OWNERDRAW) {
724 725
        if (!(oldStyle & SBT_OWNERDRAW))
            Free (part->text);
726
        part->text = text;
727 728
    } else {
	LPWSTR ntext;
729
	WCHAR  *idx;
730

731 732 733
	if (text && !isW) {
	    LPCSTR atxt = (LPCSTR)text;
            DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
734
	    ntext = Alloc( (len + 1)*sizeof(WCHAR) );
735 736 737
	    if (!ntext) return FALSE;
            MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
	} else if (text) {
738
	    ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
739 740 741 742
	    if (!ntext) return FALSE;
	    strcpyW (ntext, text);
	} else ntext = 0;

743 744 745 746 747 748 749 750 751 752
	/* replace nonprintable characters with spaces */
	if (ntext) {
	    idx = ntext;
	    while (*idx) {
	        if(!isprintW(*idx))
	            *idx = ' ';
	        idx++;
	    }
	}

753 754
	/* check if text is unchanged -> no need to redraw */
	if (text) {
755
	    if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
756
		Free(ntext);
757 758 759
		return TRUE;
	    }
	} else {
760
	    if (!changed && !part->text)
761
		return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
762 763
	}

764
	if (!(oldStyle & SBT_OWNERDRAW))
765
	    Free (part->text);
766 767
	part->text = ntext;
    }
768
    InvalidateRect(infoPtr->Self, &part->bound, FALSE);
769
    UpdateWindow(infoPtr->Self);
Alexandre Julliard's avatar
Alexandre Julliard committed
770 771

    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
772 773
}

Alexandre Julliard's avatar
Alexandre Julliard committed
774

775
static LRESULT
776
STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
777
{
778
    TRACE("part %d: \"%s\"\n", id, text);
779
    if (infoPtr->hwndToolTip) {
780 781
	TTTOOLINFOA ti;
	ti.cbSize = sizeof(TTTOOLINFOA);
782 783
	ti.hwnd = infoPtr->Self;
	ti.uId = id;
Alexandre Julliard's avatar
Alexandre Julliard committed
784
	ti.hinst = 0;
785
	ti.lpszText = text;
786
	SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
Alexandre Julliard's avatar
Alexandre Julliard committed
787 788 789 790 791 792
    }

    return 0;
}


793
static LRESULT
794
STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
795
{
796
    TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
797
    if (infoPtr->hwndToolTip) {
798 799
	TTTOOLINFOW ti;
	ti.cbSize = sizeof(TTTOOLINFOW);
800 801
	ti.hwnd = infoPtr->Self;
	ti.uId = id;
802
	ti.hinst = 0;
803
	ti.lpszText = text;
804
	SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
805 806 807 808 809 810
    }

    return 0;
}


811
static inline LRESULT
812
STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
813
{
814
    BOOL bOld = infoPtr->bUnicode;
815

816
    TRACE("(0x%x)\n", bUnicode);
817
    infoPtr->bUnicode = bUnicode;
818

819
    return bOld;
820
}
Alexandre Julliard's avatar
Alexandre Julliard committed
821 822


823
static BOOL
824
STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
Alexandre Julliard's avatar
Alexandre Julliard committed
825
{
Alexandre Julliard's avatar
Alexandre Julliard committed
826 827
    NMHDR  nmhdr;

828 829
    TRACE("(simple=%d)\n", simple);
    if (infoPtr->simple == simple) /* no need to change */
830 831
	return TRUE;

832
    infoPtr->simple = simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
833 834

    /* send notification */
835
    nmhdr.hwndFrom = infoPtr->Self;
836
    nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
837
    nmhdr.code = SBN_SIMPLEMODECHANGE;
838
    SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
839
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
840 841 842 843 844
    return TRUE;
}


static LRESULT
845
STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
Alexandre Julliard's avatar
Alexandre Julliard committed
846
{
847
    unsigned int i;
848 849 850

    TRACE("\n");
    for (i = 0; i < infoPtr->numParts; i++) {
851
	if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
852
	    Free (infoPtr->parts[i].text);
853
    }
854
    if (!(infoPtr->part0.style & SBT_OWNERDRAW))
855 856
	Free (infoPtr->part0.text);
    Free (infoPtr->parts);
857 858 859 860 861 862 863 864 865

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

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

866 867
    CloseThemeData (GetWindowTheme (infoPtr->Self));

868
    SetWindowLongPtrW(infoPtr->Self, 0, 0);
869
    Free (infoPtr);
870 871 872 873 874
    return 0;
}


static LRESULT
875
STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
876
{
877
    STATUS_INFO *infoPtr;
878
    NONCLIENTMETRICSW nclm;
879
    DWORD dwStyle;
880
    RECT rect;
881
    int	len;
Alexandre Julliard's avatar
Alexandre Julliard committed
882

883
    TRACE("\n");
884
    infoPtr = Alloc (sizeof(STATUS_INFO));
885
    if (!infoPtr) goto create_fail;
886
    SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
887

888
    infoPtr->Self = hwnd;
889
    infoPtr->Notify = lpCreate->hwndParent;
890 891 892 893 894
    infoPtr->numParts = 1;
    infoPtr->parts = 0;
    infoPtr->simple = FALSE;
    infoPtr->clrBk = CLR_DEFAULT;
    infoPtr->hFont = 0;
Filip Navara's avatar
Filip Navara committed
895 896 897
    infoPtr->horizontalBorder = HORZ_BORDER;
    infoPtr->verticalBorder = VERT_BORDER;
    infoPtr->horizontalGap = HORZ_GAP;
898 899
    infoPtr->minHeight = GetSystemMetrics(SM_CYSIZE);
    if (infoPtr->minHeight & 1) infoPtr->minHeight--;
900

901
    STATUSBAR_NotifyFormat(infoPtr, infoPtr->Notify, NF_REQUERY);
Alexandre Julliard's avatar
Alexandre Julliard committed
902

903 904 905 906
    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
907

908 909
    GetClientRect (hwnd, &rect);

Alexandre Julliard's avatar
Alexandre Julliard committed
910
    /* initialize simple case */
911 912 913 914 915
    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
916 917

    /* initialize first part */
918
    infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
919
    if (!infoPtr->parts) goto create_fail;
920 921 922 923 924
    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;
925 926
    
    OpenThemeData (hwnd, themeClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
927

928 929 930 931 932
    if (lpCreate->lpszName && (len = strlenW ((LPCWSTR)lpCreate->lpszName)))
    {
        infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
        if (!infoPtr->parts[0].text) goto create_fail;
        strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
Alexandre Julliard's avatar
Alexandre Julliard committed
933 934
    }

935
    dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
936 937 938
    /* native seems to clear WS_BORDER, too */
    dwStyle &= ~WS_BORDER;
    SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
939

940
    infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
941

942
    if (dwStyle & SBT_TOOLTIPS) {
943
	infoPtr->hwndToolTip =
944
	    CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
945 946
			     CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			     CW_USEDEFAULT, hwnd, 0,
947
			     (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
948

949
	if (infoPtr->hwndToolTip) {
Alexandre Julliard's avatar
Alexandre Julliard committed
950 951
	    NMTOOLTIPSCREATED nmttc;

952
	    nmttc.hdr.hwndFrom = hwnd;
953
	    nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
954
	    nmttc.hdr.code = NM_TOOLTIPSCREATED;
955
	    nmttc.hwndToolTips = infoPtr->hwndToolTip;
Alexandre Julliard's avatar
Alexandre Julliard committed
956

957
	    SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
958
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
959 960 961
    }

    return 0;
962

963 964 965 966
create_fail:
    TRACE("    failed!\n");
    if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
    return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
967 968 969
}


970 971
/* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
 * of the first part only (usual behaviour) */
972
static INT
973
STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
Alexandre Julliard's avatar
Alexandre Julliard committed
974
{
975
    INT len;
Alexandre Julliard's avatar
Alexandre Julliard committed
976

977
    TRACE("\n");
978
    if (!(infoPtr->parts[0].text))
Alexandre Julliard's avatar
Alexandre Julliard committed
979
        return 0;
980 981

    len = strlenW (infoPtr->parts[0].text);
982

983 984 985
    if (!size)
        return len;
    else if (size > len) {
986
        strcpyW (buf, infoPtr->parts[0].text);
987
	return len;
Alexandre Julliard's avatar
Alexandre Julliard committed
988
    }
989 990 991 992 993
    else {
        memcpy (buf, infoPtr->parts[0].text, (size - 1) * sizeof(WCHAR));
        buf[size - 1] = 0;
        return size - 1;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
994 995 996
}


997
static BOOL
998
STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
Alexandre Julliard's avatar
Alexandre Julliard committed
999
{
1000
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1001 1002
	RECT  rect;
	POINT pt;
Alexandre Julliard's avatar
Alexandre Julliard committed
1003

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

1006 1007 1008
	pt.x = x;
	pt.y = y;
	ScreenToClient (infoPtr->Self, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
1009 1010 1011 1012

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

1013
	if (PtInRect (&rect, pt))
1014 1015 1016 1017
        {
            if (GetWindowLongW( infoPtr->Self, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) return HTBOTTOMLEFT;
	    else return HTBOTTOMRIGHT;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
1018 1019
    }

1020
    return HTERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1021 1022 1023 1024
}


static LRESULT
1025
STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
1026
{
1027
    PAINTSTRUCT ps;
Alexandre Julliard's avatar
Alexandre Julliard committed
1028

1029
    TRACE("\n");
1030 1031 1032 1033
    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
1034 1035 1036 1037 1038 1039

    return 0;
}


static LRESULT
1040
STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
Alexandre Julliard's avatar
Alexandre Julliard committed
1041
{
1042
    infoPtr->hFont = font;
1043
    TRACE("%p\n", infoPtr->hFont);
1044 1045 1046

    infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
    SendMessageW(infoPtr->Self, WM_SIZE, 0, 0);  /* update size */
1047 1048
    if (redraw)
        InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1049

Alexandre Julliard's avatar
Alexandre Julliard committed
1050 1051 1052 1053
    return 0;
}


1054
static BOOL
1055
STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
Alexandre Julliard's avatar
Alexandre Julliard committed
1056 1057
{
    STATUSWINDOWPART *part;
Alexandre Julliard's avatar
Alexandre Julliard committed
1058
    int len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1059

1060
    TRACE("\n");
1061
    if (infoPtr->numParts == 0)
Alexandre Julliard's avatar
Alexandre Julliard committed
1062
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1063

1064
    part = &infoPtr->parts[0];
Alexandre Julliard's avatar
Alexandre Julliard committed
1065
    /* duplicate string */
1066
    Free (part->text);
Alexandre Julliard's avatar
Alexandre Julliard committed
1067
    part->text = 0;
1068 1069 1070 1071 1072

    if (text && (len = strlenW((LPCWSTR)text))) {
        part->text = Alloc ((len+1)*sizeof(WCHAR));
        if (!part->text) return FALSE;
        strcpyW (part->text, (LPCWSTR)text);
Alexandre Julliard's avatar
Alexandre Julliard committed
1073
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1074

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

Alexandre Julliard's avatar
Alexandre Julliard committed
1077 1078 1079
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1080

1081
static BOOL
1082
STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
Alexandre Julliard's avatar
Alexandre Julliard committed
1083
{
1084
    INT  width, x, y;
1085
    RECT parent_rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
1086

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

1090
    if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1091
	WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1092 1093
	return FALSE;
    }
1094

1095
    if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1096

1097
    /* width and height don't apply */
1098 1099 1100
    if (!GetClientRect (infoPtr->Notify, &parent_rect))
        return FALSE;

1101 1102 1103
    width = parent_rect.right - parent_rect.left;
    x = parent_rect.left;
    y = parent_rect.bottom - infoPtr->height;
1104
    MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1105 1106
    STATUSBAR_SetPartBounds (infoPtr);
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1107 1108
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1109

1110
/* update theme after a WM_THEMECHANGED message */
1111
static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1112 1113 1114 1115 1116 1117 1118 1119
{
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    CloseThemeData (theme);
    OpenThemeData (infoPtr->Self, themeClass);
    return 0;
}


1120
static LRESULT
1121
STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1122 1123
{
    if (cmd == NF_REQUERY) {
1124
	INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1125
	infoPtr->bUnicode = (i == NFR_UNICODE);
1126
    }
1127
    return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1128 1129 1130
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1131
static LRESULT
1132
STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1133
{
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
    NMMOUSE  nm;

    TRACE("code %04x, lParam=%lx\n", code, lParam);
    nm.hdr.hwndFrom = infoPtr->Self;
    nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
    nm.hdr.code = code;
    nm.pt.x = (short)LOWORD(lParam);
    nm.pt.y = (short)HIWORD(lParam);
    nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
    nm.dwItemData = 0;
    nm.dwHitInfo = 0x30000;     /* seems constant */
1145 1146 1147 1148 1149 1150

    /* Do default processing if WM_NOTIFY returns zero */
    if(!SendMessageW(infoPtr->Notify, WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm))
    {
      return DefWindowProcW(infoPtr->Self, msg, wParam, lParam);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1151 1152 1153 1154 1155
    return 0;
}



1156
static LRESULT WINAPI
1157
StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1158
{
1159
    STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1160 1161
    INT nPart = ((INT) wParam) & 0x00ff;
    LRESULT res;
1162

1163
    TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1164 1165
    if (!infoPtr && msg != WM_CREATE)
        return DefWindowProcW (hwnd, msg, wParam, lParam);
1166

Alexandre Julliard's avatar
Alexandre Julliard committed
1167
    switch (msg) {
Alexandre Julliard's avatar
Alexandre Julliard committed
1168
	case SB_GETBORDERS:
Filip Navara's avatar
Filip Navara committed
1169
	    return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1170 1171

	case SB_GETICON:
1172
	    return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1173 1174

	case SB_GETPARTS:
1175
	    return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1176 1177

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

1180
	case SB_GETTEXTA:
1181
	    return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1182

1183
	case SB_GETTEXTW:
1184
	    return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1185

1186 1187
	case SB_GETTEXTLENGTHA:
	case SB_GETTEXTLENGTHW:
1188
	    return STATUSBAR_GetTextLength (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1189

1190
	case SB_GETTIPTEXTA:
1191
	    return STATUSBAR_GetTipTextA (infoPtr,  LOWORD(wParam), (LPSTR)lParam,  HIWORD(wParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1192

1193
	case SB_GETTIPTEXTW:
1194
	    return STATUSBAR_GetTipTextW (infoPtr,  LOWORD(wParam), (LPWSTR)lParam,  HIWORD(wParam));
1195 1196

	case SB_GETUNICODEFORMAT:
1197
	    return infoPtr->bUnicode;
Alexandre Julliard's avatar
Alexandre Julliard committed
1198 1199

	case SB_ISSIMPLE:
1200
	    return infoPtr->simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
1201

Filip Navara's avatar
Filip Navara committed
1202 1203 1204
	case SB_SETBORDERS:
	    return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1205
	case SB_SETBKCOLOR:
1206
	    return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1207 1208

	case SB_SETICON:
1209
	    return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1210 1211

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

1214
	case SB_SETPARTS:
1215
	    return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1216

1217
	case SB_SETTEXTA:
1218
	    return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1219

1220
	case SB_SETTEXTW:
1221
	    return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1222

1223
	case SB_SETTIPTEXTA:
1224
	    return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1225

1226
	case SB_SETTIPTEXTW:
1227
	    return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1228 1229

	case SB_SETUNICODEFORMAT:
1230
	    return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1231 1232

	case SB_SIMPLE:
1233
	    return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1234 1235

	case WM_CREATE:
1236
	    return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1237 1238

	case WM_DESTROY:
1239
	    return STATUSBAR_WMDestroy (infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
1240 1241

	case WM_GETFONT:
1242
	    return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
1243 1244

	case WM_GETTEXT:
1245
            return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1246 1247

	case WM_GETTEXTLENGTH:
1248
	    return LOWORD(STATUSBAR_GetTextLength (infoPtr, 0));
Alexandre Julliard's avatar
Alexandre Julliard committed
1249 1250

	case WM_LBUTTONDBLCLK:
1251
            return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1252 1253

	case WM_LBUTTONUP:
1254
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1255 1256

	case WM_MOUSEMOVE:
1257
	    return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1258 1259

	case WM_NCHITTEST:
1260 1261
	    res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
                                        (short)HIWORD(lParam));
1262 1263
	    if (res != HTERROR) return res;
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1264 1265

	case WM_NCLBUTTONUP:
1266
	case WM_NCLBUTTONDOWN:
1267
    	    PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1268
	    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1269

1270 1271
	case WM_NOTIFYFORMAT:
	    return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1272

1273
	case WM_PRINTCLIENT:
Alexandre Julliard's avatar
Alexandre Julliard committed
1274
	case WM_PAINT:
1275
	    return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1276 1277

	case WM_RBUTTONDBLCLK:
1278
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1279 1280

	case WM_RBUTTONUP:
1281
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1282 1283

	case WM_SETFONT:
1284
	    return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1285 1286

	case WM_SETTEXT:
1287 1288
	    return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1289
	case WM_SIZE:
1290 1291
	    if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
            return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1292

1293 1294 1295 1296
        case WM_SYSCOLORCHANGE:
            COMCTL32_RefreshSysColors();
            return 0;

1297 1298 1299
        case WM_THEMECHANGED:
            return theme_changed (infoPtr);

Alexandre Julliard's avatar
Alexandre Julliard committed
1300
	default:
1301
	    if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
1302
		ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1303
		     msg, wParam, lParam);
1304
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1305 1306 1307 1308
    }
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1309
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1310
 * STATUS_Register [Internal]
Alexandre Julliard's avatar
Alexandre Julliard committed
1311 1312 1313
 *
 * Registers the status window class.
 */
1314

1315
void
1316
STATUS_Register (void)
Alexandre Julliard's avatar
Alexandre Julliard committed
1317
{
1318
    WNDCLASSW wndClass;
Alexandre Julliard's avatar
Alexandre Julliard committed
1319

1320
    ZeroMemory (&wndClass, sizeof(WNDCLASSW));
Alexandre Julliard's avatar
Alexandre Julliard committed
1321
    wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1322
    wndClass.lpfnWndProc   = StatusWindowProc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1323
    wndClass.cbClsExtra    = 0;
1324
    wndClass.cbWndExtra    = sizeof(STATUS_INFO *);
1325
    wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1326
    wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1327
    wndClass.lpszClassName = STATUSCLASSNAMEW;
1328

1329
    RegisterClassW (&wndClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
1330
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1331

1332 1333 1334 1335 1336 1337 1338

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

1339
void
1340
STATUS_Unregister (void)
1341
{
1342
    UnregisterClassW (STATUSCLASSNAMEW, NULL);
1343
}