status.c 35 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
 * 	-- CCS_BOTTOM (default)
 * 	-- CCS_LEFT
34
 * 	-- CCS_NODIVIDER
35 36 37 38 39 40
 * 	-- 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
#include "uxtheme.h"
55
#include "vssym32.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
    UINT              height;
75
    UINT              minHeight;        /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
76 77 78 79
    BOOL              simple;
    HWND              hwndToolTip;
    HFONT             hFont;
    HFONT             hDefaultFont;
80
    COLORREF          clrBk;		/* background color */
81
    BOOL              bUnicode;         /* notify format. TRUE if notifies in Unicode */
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
static LRESULT
STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd);
106 107 108 109 110

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
111

112 113 114 115 116 117
static UINT
STATUSBAR_ComputeHeight(STATUS_INFO *infoPtr)
{
    HTHEME theme;
    UINT height;
    TEXTMETRICW tm;
118
    int margin;
119 120

    COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm);
121
    margin = (tm.tmInternalLeading ? tm.tmInternalLeading : 2);
122
    height = max(tm.tmHeight + margin + 2*GetSystemMetrics(SM_CYBORDER), infoPtr->minHeight) + infoPtr->verticalBorder;
123 124 125 126 127 128 129 130

    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;
        memset (&r, 0, sizeof (r));
131
        r.bottom = max(infoPtr->minHeight, tm.tmHeight);
132 133 134 135 136 137 138 139 140 141 142
        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
143
static void
144
STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
Alexandre Julliard's avatar
Alexandre Julliard committed
145
{
146
    HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
147 148
    POINT pt;
    INT i;
Alexandre Julliard's avatar
Alexandre Julliard committed
149

150 151
    TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect));

152 153 154 155 156 157 158 159 160 161 162 163 164 165
    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;
        }
    }
166

Alexandre Julliard's avatar
Alexandre Julliard committed
167 168 169
    pt.x = lpRect->right - 1;
    pt.y = lpRect->bottom - 1;

170
    hPenFace = CreatePen( PS_SOLID, 1, comctl32_color.clr3dFace);
171
    hOldPen = SelectObject( hdc, hPenFace );
172 173
    MoveToEx (hdc, pt.x - 12, pt.y, NULL);
    LineTo (hdc, pt.x, pt.y);
174
    LineTo (hdc, pt.x, pt.y - 13);
Alexandre Julliard's avatar
Alexandre Julliard committed
175 176 177 178

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

179
    hPenShadow = CreatePen( PS_SOLID, 1, comctl32_color.clr3dShadow);
180
    SelectObject( hdc, hPenShadow );
Alexandre Julliard's avatar
Alexandre Julliard committed
181
    for (i = 1; i < 11; i += 4) {
182
	MoveToEx (hdc, pt.x - i, pt.y, NULL);
183
	LineTo (hdc, pt.x + 1, pt.y - i - 1);
Alexandre Julliard's avatar
Alexandre Julliard committed
184

185 186
	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
187
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
188

189
    hPenHighlight = CreatePen( PS_SOLID, 1, comctl32_color.clr3dHilight);
190
    SelectObject( hdc, hPenHighlight );
Alexandre Julliard's avatar
Alexandre Julliard committed
191
    for (i = 3; i < 13; i += 4) {
192
	MoveToEx (hdc, pt.x - i, pt.y, NULL);
193
	LineTo (hdc, pt.x + 1, pt.y - i - 1);
Alexandre Julliard's avatar
Alexandre Julliard committed
194 195
    }

196 197 198 199
    SelectObject (hdc, hOldPen);
    DeleteObject( hPenFace );
    DeleteObject( hPenShadow );
    DeleteObject( hPenHighlight );
Alexandre Julliard's avatar
Alexandre Julliard committed
200 201 202
}


203
static void
204
STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
Alexandre Julliard's avatar
Alexandre Julliard committed
205
{
206 207
    RECT r = part->bound;
    UINT border = BDR_SUNKENOUTER;
208 209
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    int themePart = SP_PANE;
210
    int x = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
211

212
    TRACE("part bound %s\n", wine_dbgstr_rect(&r));
213
    if (part->style & SBT_POPOUT)
214
        border = BDR_RAISEDOUTER;
215
    else if (part->style & SBT_NOBORDERS)
216
        border = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
217

218 219 220 221 222 223 224 225 226
    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);
227

228 229 230 231 232 233
    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;
    }

234 235 236 237 238 239 240 241
    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
242
	dis.itemData = (ULONG_PTR)part->text;
243
        SendMessageW (infoPtr->Notify, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
244
    } else {
245
        r.left += x;
246
        DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
Alexandre Julliard's avatar
Alexandre Julliard committed
247 248 249 250
    }
}


251
static void
252
STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
Alexandre Julliard's avatar
Alexandre Julliard committed
253
{
254
    HBRUSH hbrBk;
255
    HTHEME theme;
Alexandre Julliard's avatar
Alexandre Julliard committed
256

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

259 260
    if (part->bound.right < part->bound.left) return;

261 262 263
    if (!RectVisible(hdc, &part->bound))
        return;

264 265 266 267 268 269
    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
270
    else
271 272 273 274 275 276 277 278 279
    {
        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
280

281
    STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
Alexandre Julliard's avatar
Alexandre Julliard committed
282 283 284
}


285
static LRESULT
286
STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
287 288
{
    int      i;
289 290 291
    RECT   rect;
    HBRUSH hbrBk;
    HFONT  hOldFont;
292
    HTHEME theme;
Alexandre Julliard's avatar
Alexandre Julliard committed
293

294
    TRACE("\n");
295 296
    if (!IsWindowVisible(infoPtr->Self))
        return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
297

298
    STATUSBAR_SetPartBounds(infoPtr);
299

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

302 303 304 305
    if ((theme = GetWindowTheme (infoPtr->Self)))
    {
        DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
306
    else
307 308 309 310 311 312 313 314 315
    {
        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
316

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

319
    if (infoPtr->simple) {
320
	STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
321
    } else {
322 323 324
	for (i = 0; i < infoPtr->numParts; i++) {
	    STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
325 326
    }

327
    SelectObject (hdc, hOldFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
328

329
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
330
	    STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
331

332
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
333 334 335
}


336
static int
337
STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const POINT *pt)
338 339 340 341 342 343 344 345 346 347 348 349
{
    int i;
    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
350
static void
351
STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
Alexandre Julliard's avatar
Alexandre Julliard committed
352 353
{
    STATUSWINDOWPART *part;
354
    RECT rect, *r;
Alexandre Julliard's avatar
Alexandre Julliard committed
355
    int	i;
Alexandre Julliard's avatar
Alexandre Julliard committed
356 357

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

Filip Navara's avatar
Filip Navara committed
361 362
    rect.left += infoPtr->horizontalBorder;
    rect.top += infoPtr->verticalBorder;
Alexandre Julliard's avatar
Alexandre Julliard committed
363

Alexandre Julliard's avatar
Alexandre Julliard committed
364
    /* set bounds for simple rectangle */
365
    infoPtr->part0.bound = rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
366 367

    /* set bounds for non-simple rectangles */
368 369 370
    for (i = 0; i < infoPtr->numParts; i++) {
	part = &infoPtr->parts[i];
	r = &infoPtr->parts[i].bound;
Alexandre Julliard's avatar
Alexandre Julliard committed
371 372 373 374 375
	r->top = rect.top;
	r->bottom = rect.bottom;
	if (i == 0)
	    r->left = 0;
	else
Filip Navara's avatar
Filip Navara committed
376
	    r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
Alexandre Julliard's avatar
Alexandre Julliard committed
377 378 379 380
	if (part->x == -1)
	    r->right = rect.right;
	else
	    r->right = part->x;
Alexandre Julliard's avatar
Alexandre Julliard committed
381

382
	if (infoPtr->hwndToolTip) {
383
	    TTTOOLINFOW ti;
Alexandre Julliard's avatar
Alexandre Julliard committed
384

385 386
	    ti.cbSize = sizeof(TTTOOLINFOW);
	    ti.hwnd = infoPtr->Self;
Alexandre Julliard's avatar
Alexandre Julliard committed
387 388
	    ti.uId = i;
	    ti.rect = *r;
389
	    SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
Alexandre Julliard's avatar
Alexandre Julliard committed
390 391
			    0, (LPARAM)&ti);
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
392 393 394
    }
}

Alexandre Julliard's avatar
Alexandre Julliard committed
395

396
static LRESULT
397
STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
398
		     WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
399
{
400
    MSG msg;
Alexandre Julliard's avatar
Alexandre Julliard committed
401

402
    msg.hwnd = infoPtr->Self;
Alexandre Julliard's avatar
Alexandre Julliard committed
403 404 405 406
    msg.message = uMsg;
    msg.wParam = wParam;
    msg.lParam = lParam;
    msg.time = GetMessageTime ();
407 408
    msg.pt.x = (short)LOWORD(GetMessagePos ());
    msg.pt.y = (short)HIWORD(GetMessagePos ());
Alexandre Julliard's avatar
Alexandre Julliard committed
409

410
    return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
Alexandre Julliard's avatar
Alexandre Julliard committed
411 412 413
}


414
static BOOL
415
STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
Alexandre Julliard's avatar
Alexandre Julliard committed
416
{
417
    TRACE("\n");
Filip Navara's avatar
Filip Navara committed
418 419 420 421 422 423 424 425 426
    out[0] = infoPtr->horizontalBorder;
    out[1] = infoPtr->verticalBorder;
    out[2] = infoPtr->horizontalGap;

    return TRUE;
}


static BOOL
427
STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
Filip Navara's avatar
Filip Navara committed
428 429 430 431 432 433
{
    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
434 435 436 437

    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
438

439
static HICON
440
STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
Alexandre Julliard's avatar
Alexandre Julliard committed
441
{
442
    TRACE("%d\n", nPart);
443
    /* MSDN says: "simple parts are indexed with -1" */
444
    if ((nPart < -1) || (nPart >= infoPtr->numParts))
445
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
446

Alexandre Julliard's avatar
Alexandre Julliard committed
447
    if (nPart == -1)
448
        return (infoPtr->part0.hIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
449
    else
450
        return (infoPtr->parts[nPart].hIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
451 452
}

Alexandre Julliard's avatar
Alexandre Julliard committed
453

454
static INT
455
STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
Alexandre Julliard's avatar
Alexandre Julliard committed
456
{
457
    INT   i;
Alexandre Julliard's avatar
Alexandre Julliard committed
458

459
    TRACE("(%d)\n", num_parts);
Alexandre Julliard's avatar
Alexandre Julliard committed
460 461
    if (parts) {
	for (i = 0; i < num_parts; i++) {
462
	    parts[i] = infoPtr->parts[i].x;
Alexandre Julliard's avatar
Alexandre Julliard committed
463 464
	}
    }
465
    return infoPtr->numParts;
Alexandre Julliard's avatar
Alexandre Julliard committed
466 467 468
}


469
static BOOL
470
STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
Alexandre Julliard's avatar
Alexandre Julliard committed
471
{
472
    TRACE("part %d\n", nPart);
473 474
    if(nPart >= infoPtr->numParts || nPart < 0)
      return FALSE;
475 476
    if (infoPtr->simple)
	*rect = infoPtr->part0.bound;
Alexandre Julliard's avatar
Alexandre Julliard committed
477
    else
478
	*rect = infoPtr->parts[nPart].bound;
Alexandre Julliard's avatar
Alexandre Julliard committed
479 480 481
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
482

Alexandre Julliard's avatar
Alexandre Julliard committed
483
static LRESULT
484
STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
Alexandre Julliard's avatar
Alexandre Julliard committed
485 486
{
    STATUSWINDOWPART *part;
Alexandre Julliard's avatar
Alexandre Julliard committed
487
    LRESULT result;
Alexandre Julliard's avatar
Alexandre Julliard committed
488

489
    TRACE("part %d\n", nPart);
490 491

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

494 495
    if (infoPtr->simple)
	part = &infoPtr->part0;
Alexandre Julliard's avatar
Alexandre Julliard committed
496
    else
497
	part = &infoPtr->parts[nPart];
Alexandre Julliard's avatar
Alexandre Julliard committed
498

499
    if (part->style & SBT_OWNERDRAW)
500
	result = (LRESULT)part->text;
Alexandre Julliard's avatar
Alexandre Julliard committed
501
    else {
502 503 504
        DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
                                                      NULL, 0, NULL, NULL ) - 1 : 0;
        result = MAKELONG( len, part->style );
505 506
        if (part->text && buf)
            WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
Alexandre Julliard's avatar
Alexandre Julliard committed
507 508 509 510
    }
    return result;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
511

512
static LRESULT
513
STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
514 515 516 517
{
    STATUSWINDOWPART *part;
    LRESULT result;

518
    TRACE("part %d\n", nPart);
519 520
    if (nPart < 0 || nPart >= infoPtr->numParts) return 0;

521 522
    if (infoPtr->simple)
	part = &infoPtr->part0;
523
    else
524
	part = &infoPtr->parts[nPart];
525

526
    if (part->style & SBT_OWNERDRAW)
527 528
	result = (LRESULT)part->text;
    else {
529
	result = part->text ? strlenW (part->text) : 0;
530
	result |= (part->style << 16);
531 532
	if (part->text && buf)
	    strcpyW (buf, part->text);
533 534 535
    }
    return result;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
536 537


Alexandre Julliard's avatar
Alexandre Julliard committed
538
static LRESULT
539
STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
Alexandre Julliard's avatar
Alexandre Julliard committed
540 541
{
    STATUSWINDOWPART *part;
542
    DWORD result;
Alexandre Julliard's avatar
Alexandre Julliard committed
543

544
    TRACE("part %d\n", nPart);
545 546 547 548

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

549 550
    if (infoPtr->simple)
	part = &infoPtr->part0;
Alexandre Julliard's avatar
Alexandre Julliard committed
551
    else
552
	part = &infoPtr->parts[nPart];
Alexandre Julliard's avatar
Alexandre Julliard committed
553

554
    if ((~part->style & SBT_OWNERDRAW) && part->text)
555
	result = strlenW(part->text);
Alexandre Julliard's avatar
Alexandre Julliard committed
556 557 558 559 560 561 562 563
    else
	result = 0;

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

static LRESULT
564
STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
Alexandre Julliard's avatar
Alexandre Julliard committed
565
{
566
    TRACE("\n");
567 568 569 570 571 572 573
    if (tip) {
        CHAR buf[INFOTIPSIZE];
        buf[0]='\0';

        if (infoPtr->hwndToolTip) {
            TTTOOLINFOA ti;
            ti.cbSize = sizeof(TTTOOLINFOA);
574 575
            ti.hwnd = infoPtr->Self;
            ti.uId = id;
576
            ti.lpszText = buf;
577
            SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
578
        }
579
        lstrcpynA (tip, buf, size);
Alexandre Julliard's avatar
Alexandre Julliard committed
580
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
581
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
582 583
}

Alexandre Julliard's avatar
Alexandre Julliard committed
584

585
static LRESULT
586
STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
587
{
588
    TRACE("\n");
589 590 591
    if (tip) {
        WCHAR buf[INFOTIPSIZE];
        buf[0]=0;
592

593 594 595
	if (infoPtr->hwndToolTip) {
	    TTTOOLINFOW ti;
	    ti.cbSize = sizeof(TTTOOLINFOW);
596 597
	    ti.hwnd = infoPtr->Self;
	    ti.uId = id;
598 599 600
            ti.lpszText = buf;
	    SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
	}
601
	lstrcpynW(tip, buf, size);
602 603 604 605 606 607
    }

    return 0;
}


608
static COLORREF
609
STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
Alexandre Julliard's avatar
Alexandre Julliard committed
610 611 612
{
    COLORREF oldBkColor;

613
    oldBkColor = infoPtr->clrBk;
614 615
    infoPtr->clrBk = color;
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
616

617
    TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
Alexandre Julliard's avatar
Alexandre Julliard committed
618 619 620 621
    return oldBkColor;
}


622
static BOOL
623
STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
Alexandre Julliard's avatar
Alexandre Julliard committed
624
{
625
    if ((nPart < -1) || (nPart >= infoPtr->numParts))
626
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
627

628
    TRACE("setting part %d\n", nPart);
629

630
    /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
Alexandre Julliard's avatar
Alexandre Julliard committed
631
    if (nPart == -1) {
632
	if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
633
	    return TRUE;
634
	infoPtr->part0.hIcon = hIcon;
635
	if (infoPtr->simple)
636
            InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
637
    } else {
638
	if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
639 640
	    return TRUE;

641
	infoPtr->parts[nPart].hIcon = hIcon;
642
	if (!(infoPtr->simple))
643
            InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
644
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
645 646 647
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
648

649
static BOOL
650
STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
Alexandre Julliard's avatar
Alexandre Julliard committed
651
{
652 653 654
    DWORD ysize = GetSystemMetrics(SM_CYSIZE);
    if (ysize & 1) ysize--;
    infoPtr->minHeight = max(height, ysize);
655 656
    infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
    /* like native, don't resize the control */
Alexandre Julliard's avatar
Alexandre Julliard committed
657 658 659 660
    return TRUE;
}


661
static BOOL
662
STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
Alexandre Julliard's avatar
Alexandre Julliard committed
663
{
664
    STATUSWINDOWPART *tmp;
665
    INT i, oldNumParts;
Alexandre Julliard's avatar
Alexandre Julliard committed
666

667
    TRACE("(%d,%p)\n", count, parts);
668

669 670
    if(!count) return FALSE;

671
    oldNumParts = infoPtr->numParts;
672
    infoPtr->numParts = count;
673 674
    if (oldNumParts > infoPtr->numParts) {
	for (i = infoPtr->numParts ; i < oldNumParts; i++) {
675
	    if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
676
		Free (infoPtr->parts[i].text);
Alexandre Julliard's avatar
Alexandre Julliard committed
677
	}
678
    } else if (oldNumParts < infoPtr->numParts) {
679
	tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
680
	if (!tmp) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
681
	for (i = 0; i < oldNumParts; i++) {
682
	    tmp[i] = infoPtr->parts[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
683
	}
684
        Free (infoPtr->parts);
685
	infoPtr->parts = tmp;
Alexandre Julliard's avatar
Alexandre Julliard committed
686
    }
687
    if (oldNumParts == infoPtr->numParts) {
688
	for (i=0; i < oldNumParts; i++)
689
	    if (infoPtr->parts[i].x != parts[i])
690 691 692 693
		break;
	if (i==oldNumParts) /* Unchanged? no need to redraw! */
	    return TRUE;
    }
694

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

698
    if (infoPtr->hwndToolTip) {
699
	INT nTipCount;
700 701 702 703 704
	TTTOOLINFOW ti;

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

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


732
static BOOL
733
STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
734
		    LPWSTR text, BOOL isW)
Alexandre Julliard's avatar
Alexandre Julliard committed
735
{
736
    STATUSWINDOWPART *part=NULL;
737
    BOOL changed = FALSE;
738
    INT  oldStyle;
Alexandre Julliard's avatar
Alexandre Julliard committed
739

740
    if (style & SBT_OWNERDRAW) {
Gerald Pfeifer's avatar
Gerald Pfeifer committed
741
         TRACE("part %d, text %p\n",nPart,text);
742 743
    }
    else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
744

745 746 747 748
    /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
     * window is assumed to be a simple window */

    if (nPart == 0x00ff) {
749
	part = &infoPtr->part0;
750
    } else {
751
	if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
752 753 754
	    part = &infoPtr->parts[nPart];
	}
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
755
    if (!part) return FALSE;
756

757 758
    if (part->style != style)
	changed = TRUE;
759

760
    oldStyle = part->style;
761
    part->style = style;
762
    if (style & SBT_OWNERDRAW) {
763 764
        if (!(oldStyle & SBT_OWNERDRAW))
            Free (part->text);
765
        part->text = text;
766 767
    } else {
	LPWSTR ntext;
768
	WCHAR  *idx;
769

770 771 772
	if (text && !isW) {
	    LPCSTR atxt = (LPCSTR)text;
            DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
773
	    ntext = Alloc( (len + 1)*sizeof(WCHAR) );
774 775 776
	    if (!ntext) return FALSE;
            MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
	} else if (text) {
777
	    ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
778 779 780 781
	    if (!ntext) return FALSE;
	    strcpyW (ntext, text);
	} else ntext = 0;

782 783 784 785 786 787 788 789 790 791
	/* replace nonprintable characters with spaces */
	if (ntext) {
	    idx = ntext;
	    while (*idx) {
	        if(!isprintW(*idx))
	            *idx = ' ';
	        idx++;
	    }
	}

792 793
	/* check if text is unchanged -> no need to redraw */
	if (text) {
794
	    if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
795
		Free(ntext);
796 797 798
		return TRUE;
	    }
	} else {
799
	    if (!changed && !part->text)
800
		return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
801 802
	}

803
	if (!(oldStyle & SBT_OWNERDRAW))
804
	    Free (part->text);
805 806
	part->text = ntext;
    }
807
    InvalidateRect(infoPtr->Self, &part->bound, FALSE);
808
    UpdateWindow(infoPtr->Self);
Alexandre Julliard's avatar
Alexandre Julliard committed
809 810

    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
811 812
}

Alexandre Julliard's avatar
Alexandre Julliard committed
813

814
static LRESULT
815
STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
816
{
817
    TRACE("part %d: \"%s\"\n", id, text);
818
    if (infoPtr->hwndToolTip) {
819 820
	TTTOOLINFOA ti;
	ti.cbSize = sizeof(TTTOOLINFOA);
821 822
	ti.hwnd = infoPtr->Self;
	ti.uId = id;
Alexandre Julliard's avatar
Alexandre Julliard committed
823
	ti.hinst = 0;
824
	ti.lpszText = text;
825
	SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
Alexandre Julliard's avatar
Alexandre Julliard committed
826 827 828 829 830 831
    }

    return 0;
}


832
static LRESULT
833
STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
834
{
835
    TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
836
    if (infoPtr->hwndToolTip) {
837 838
	TTTOOLINFOW ti;
	ti.cbSize = sizeof(TTTOOLINFOW);
839 840
	ti.hwnd = infoPtr->Self;
	ti.uId = id;
841
	ti.hinst = 0;
842
	ti.lpszText = text;
843
	SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
844 845 846 847 848 849
    }

    return 0;
}


850
static inline LRESULT
851
STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
852
{
853
    BOOL bOld = infoPtr->bUnicode;
854

855
    TRACE("(0x%x)\n", bUnicode);
856
    infoPtr->bUnicode = bUnicode;
857

858
    return bOld;
859
}
Alexandre Julliard's avatar
Alexandre Julliard committed
860 861


862
static BOOL
863
STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
Alexandre Julliard's avatar
Alexandre Julliard committed
864
{
Alexandre Julliard's avatar
Alexandre Julliard committed
865 866
    NMHDR  nmhdr;

867 868
    TRACE("(simple=%d)\n", simple);
    if (infoPtr->simple == simple) /* no need to change */
869 870
	return TRUE;

871
    infoPtr->simple = simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
872 873

    /* send notification */
874
    nmhdr.hwndFrom = infoPtr->Self;
875
    nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
876
    nmhdr.code = SBN_SIMPLEMODECHANGE;
877
    SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
878
    InvalidateRect(infoPtr->Self, NULL, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
879 880 881 882 883
    return TRUE;
}


static LRESULT
884
STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
Alexandre Julliard's avatar
Alexandre Julliard committed
885
{
886 887 888 889
    int	i;

    TRACE("\n");
    for (i = 0; i < infoPtr->numParts; i++) {
890
	if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
891
	    Free (infoPtr->parts[i].text);
892
    }
893
    if (!(infoPtr->part0.style & SBT_OWNERDRAW))
894 895
	Free (infoPtr->part0.text);
    Free (infoPtr->parts);
896 897 898 899 900 901 902 903 904

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

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

905 906
    CloseThemeData (GetWindowTheme (infoPtr->Self));

907
    SetWindowLongPtrW(infoPtr->Self, 0, 0);
908
    Free (infoPtr);
909 910 911 912 913
    return 0;
}


static LRESULT
914
STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
915
{
916
    STATUS_INFO *infoPtr;
917
    NONCLIENTMETRICSW nclm;
918
    DWORD dwStyle;
919
    RECT rect;
920
    int	len;
Alexandre Julliard's avatar
Alexandre Julliard committed
921

922
    TRACE("\n");
923
    infoPtr = Alloc (sizeof(STATUS_INFO));
924
    if (!infoPtr) goto create_fail;
925
    SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
926

927
    infoPtr->Self = hwnd;
928
    infoPtr->Notify = lpCreate->hwndParent;
929 930 931 932 933
    infoPtr->numParts = 1;
    infoPtr->parts = 0;
    infoPtr->simple = FALSE;
    infoPtr->clrBk = CLR_DEFAULT;
    infoPtr->hFont = 0;
Filip Navara's avatar
Filip Navara committed
934 935 936
    infoPtr->horizontalBorder = HORZ_BORDER;
    infoPtr->verticalBorder = VERT_BORDER;
    infoPtr->horizontalGap = HORZ_GAP;
937 938
    infoPtr->minHeight = GetSystemMetrics(SM_CYSIZE);
    if (infoPtr->minHeight & 1) infoPtr->minHeight--;
939

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

942 943 944 945
    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
946

947 948
    GetClientRect (hwnd, &rect);

Alexandre Julliard's avatar
Alexandre Julliard committed
949
    /* initialize simple case */
950 951 952 953 954
    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
955 956

    /* initialize first part */
957
    infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
958
    if (!infoPtr->parts) goto create_fail;
959 960 961 962 963
    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;
964 965
    
    OpenThemeData (hwnd, themeClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
966

967 968 969 970 971
    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
972 973
    }

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

979
    infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
980

981
    if (dwStyle & SBT_TOOLTIPS) {
982
	infoPtr->hwndToolTip =
983
	    CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
984 985
			     CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			     CW_USEDEFAULT, hwnd, 0,
986
			     (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
987

988
	if (infoPtr->hwndToolTip) {
Alexandre Julliard's avatar
Alexandre Julliard committed
989 990
	    NMTOOLTIPSCREATED nmttc;

991
	    nmttc.hdr.hwndFrom = hwnd;
992
	    nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
993
	    nmttc.hdr.code = NM_TOOLTIPSCREATED;
994
	    nmttc.hwndToolTips = infoPtr->hwndToolTip;
Alexandre Julliard's avatar
Alexandre Julliard committed
995

996
	    SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
997
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
998 999 1000
    }

    return 0;
1001

1002 1003 1004 1005
create_fail:
    TRACE("    failed!\n");
    if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
    return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
1006 1007 1008
}


1009 1010
/* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
 * of the first part only (usual behaviour) */
1011
static INT
1012
STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
Alexandre Julliard's avatar
Alexandre Julliard committed
1013
{
1014
    INT len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1015

1016
    TRACE("\n");
1017
    if (!(infoPtr->parts[0].text))
Alexandre Julliard's avatar
Alexandre Julliard committed
1018
        return 0;
1019 1020

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

1022 1023 1024
    if (!size)
        return len;
    else if (size > len) {
1025
        strcpyW (buf, infoPtr->parts[0].text);
1026
	return len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1027
    }
1028 1029 1030 1031 1032
    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
1033 1034 1035
}


1036
static BOOL
1037
STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
Alexandre Julliard's avatar
Alexandre Julliard committed
1038
{
1039
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1040 1041
	RECT  rect;
	POINT pt;
Alexandre Julliard's avatar
Alexandre Julliard committed
1042

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

1045 1046 1047
	pt.x = x;
	pt.y = y;
	ScreenToClient (infoPtr->Self, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
1048 1049 1050 1051

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

1052
	if (PtInRect (&rect, pt))
1053 1054 1055 1056
        {
            if (GetWindowLongW( infoPtr->Self, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) return HTBOTTOMLEFT;
	    else return HTBOTTOMRIGHT;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
1057 1058
    }

1059
    return HTERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1060 1061 1062 1063
}


static LRESULT
1064
STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
1065
{
1066
    PAINTSTRUCT ps;
Alexandre Julliard's avatar
Alexandre Julliard committed
1067

1068
    TRACE("\n");
1069 1070 1071 1072
    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
1073 1074 1075 1076 1077 1078

    return 0;
}


static LRESULT
1079
STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
Alexandre Julliard's avatar
Alexandre Julliard committed
1080
{
1081
    infoPtr->hFont = font;
1082
    TRACE("%p\n", infoPtr->hFont);
1083 1084 1085

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

Alexandre Julliard's avatar
Alexandre Julliard committed
1089 1090 1091 1092
    return 0;
}


1093
static BOOL
1094
STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
Alexandre Julliard's avatar
Alexandre Julliard committed
1095 1096
{
    STATUSWINDOWPART *part;
Alexandre Julliard's avatar
Alexandre Julliard committed
1097
    int len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1098

1099
    TRACE("\n");
1100
    if (infoPtr->numParts == 0)
Alexandre Julliard's avatar
Alexandre Julliard committed
1101
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1102

1103
    part = &infoPtr->parts[0];
Alexandre Julliard's avatar
Alexandre Julliard committed
1104
    /* duplicate string */
1105
    Free (part->text);
Alexandre Julliard's avatar
Alexandre Julliard committed
1106
    part->text = 0;
1107 1108 1109 1110 1111

    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
1112
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1113

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

Alexandre Julliard's avatar
Alexandre Julliard committed
1116 1117 1118
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1119

1120
static BOOL
1121
STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
Alexandre Julliard's avatar
Alexandre Julliard committed
1122
{
1123
    INT  width, x, y;
1124
    RECT parent_rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
1125

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

1129
    if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1130
	WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1131 1132
	return FALSE;
    }
1133

1134
    if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1135

1136
    /* width and height don't apply */
1137 1138 1139
    if (!GetClientRect (infoPtr->Notify, &parent_rect))
        return FALSE;

1140 1141 1142
    width = parent_rect.right - parent_rect.left;
    x = parent_rect.left;
    y = parent_rect.bottom - infoPtr->height;
1143
    MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1144 1145
    STATUSBAR_SetPartBounds (infoPtr);
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1146 1147
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1148

1149
/* update theme after a WM_THEMECHANGED message */
1150
static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1151 1152 1153 1154 1155 1156 1157 1158
{
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    CloseThemeData (theme);
    OpenThemeData (infoPtr->Self, themeClass);
    return 0;
}


1159
static LRESULT
1160
STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1161 1162
{
    if (cmd == NF_REQUERY) {
1163
	INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1164
	infoPtr->bUnicode = (i == NFR_UNICODE);
1165
    }
1166
    return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1167 1168 1169
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1170
static LRESULT
1171
STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1172
{
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
    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 */
1184 1185 1186 1187 1188 1189

    /* 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
1190 1191 1192 1193 1194
    return 0;
}



1195
static LRESULT WINAPI
1196
StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1197
{
1198
    STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1199 1200
    INT nPart = ((INT) wParam) & 0x00ff;
    LRESULT res;
1201

1202
    TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1203 1204
    if (!infoPtr && msg != WM_CREATE)
        return DefWindowProcW (hwnd, msg, wParam, lParam);
1205

Alexandre Julliard's avatar
Alexandre Julliard committed
1206
    switch (msg) {
Alexandre Julliard's avatar
Alexandre Julliard committed
1207
	case SB_GETBORDERS:
Filip Navara's avatar
Filip Navara committed
1208
	    return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1209 1210

	case SB_GETICON:
1211
	    return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1212 1213

	case SB_GETPARTS:
1214
	    return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1215 1216

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

1219
	case SB_GETTEXTA:
1220
	    return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1221

1222
	case SB_GETTEXTW:
1223
	    return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1224

1225 1226
	case SB_GETTEXTLENGTHA:
	case SB_GETTEXTLENGTHW:
1227
	    return STATUSBAR_GetTextLength (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1228

1229
	case SB_GETTIPTEXTA:
1230
	    return STATUSBAR_GetTipTextA (infoPtr,  LOWORD(wParam), (LPSTR)lParam,  HIWORD(wParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1231

1232
	case SB_GETTIPTEXTW:
1233
	    return STATUSBAR_GetTipTextW (infoPtr,  LOWORD(wParam), (LPWSTR)lParam,  HIWORD(wParam));
1234 1235

	case SB_GETUNICODEFORMAT:
1236
	    return infoPtr->bUnicode;
Alexandre Julliard's avatar
Alexandre Julliard committed
1237 1238

	case SB_ISSIMPLE:
1239
	    return infoPtr->simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
1240

Filip Navara's avatar
Filip Navara committed
1241 1242 1243
	case SB_SETBORDERS:
	    return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1244
	case SB_SETBKCOLOR:
1245
	    return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1246 1247

	case SB_SETICON:
1248
	    return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1249 1250

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

1253
	case SB_SETPARTS:
1254
	    return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1255

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

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

1262
	case SB_SETTIPTEXTA:
1263
	    return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1264

1265
	case SB_SETTIPTEXTW:
1266
	    return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1267 1268

	case SB_SETUNICODEFORMAT:
1269
	    return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1270 1271

	case SB_SIMPLE:
1272
	    return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1273 1274

	case WM_CREATE:
1275
	    return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1276 1277

	case WM_DESTROY:
1278
	    return STATUSBAR_WMDestroy (infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
1279 1280

	case WM_GETFONT:
1281
	    return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
1282 1283

	case WM_GETTEXT:
1284
            return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1285 1286

	case WM_GETTEXTLENGTH:
1287
	    return LOWORD(STATUSBAR_GetTextLength (infoPtr, 0));
Alexandre Julliard's avatar
Alexandre Julliard committed
1288 1289

	case WM_LBUTTONDBLCLK:
1290
            return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1291 1292

	case WM_LBUTTONUP:
1293
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1294 1295

	case WM_MOUSEMOVE:
1296
	    return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1297 1298

	case WM_NCHITTEST:
1299 1300
	    res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
                                        (short)HIWORD(lParam));
1301 1302
	    if (res != HTERROR) return res;
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1303 1304

	case WM_NCLBUTTONUP:
1305
	case WM_NCLBUTTONDOWN:
1306
    	    PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1307
	    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1308

1309 1310
	case WM_NOTIFYFORMAT:
	    return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1311

1312
	case WM_PRINTCLIENT:
Alexandre Julliard's avatar
Alexandre Julliard committed
1313
	case WM_PAINT:
1314
	    return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1315 1316

	case WM_RBUTTONDBLCLK:
1317
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1318 1319

	case WM_RBUTTONUP:
1320
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1321 1322

	case WM_SETFONT:
1323
	    return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1324 1325

	case WM_SETTEXT:
1326 1327
	    return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1328
	case WM_SIZE:
1329 1330
	    if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
            return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1331

1332 1333 1334 1335
        case WM_SYSCOLORCHANGE:
            COMCTL32_RefreshSysColors();
            return 0;

1336 1337 1338
        case WM_THEMECHANGED:
            return theme_changed (infoPtr);

Alexandre Julliard's avatar
Alexandre Julliard committed
1339
	default:
1340
	    if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
1341
		ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1342
		     msg, wParam, lParam);
1343
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1344 1345 1346 1347
    }
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1348
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1349
 * STATUS_Register [Internal]
Alexandre Julliard's avatar
Alexandre Julliard committed
1350 1351 1352
 *
 * Registers the status window class.
 */
1353

1354
void
1355
STATUS_Register (void)
Alexandre Julliard's avatar
Alexandre Julliard committed
1356
{
1357
    WNDCLASSW wndClass;
Alexandre Julliard's avatar
Alexandre Julliard committed
1358

1359
    ZeroMemory (&wndClass, sizeof(WNDCLASSW));
Alexandre Julliard's avatar
Alexandre Julliard committed
1360
    wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1361
    wndClass.lpfnWndProc   = StatusWindowProc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1362
    wndClass.cbClsExtra    = 0;
1363
    wndClass.cbWndExtra    = sizeof(STATUS_INFO *);
1364
    wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1365
    wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1366
    wndClass.lpszClassName = STATUSCLASSNAMEW;
1367

1368
    RegisterClassW (&wndClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
1369
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1370

1371 1372 1373 1374 1375 1376 1377

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

1378
void
1379
STATUS_Unregister (void)
1380
{
1381
    UnregisterClassW (STATUSCLASSNAMEW, NULL);
1382
}