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

58
WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
59 60 61

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

typedef struct
{
71
    HWND              Self;
72
    HWND              Notify;
73
    WORD              numParts;
74
    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
#define HORZ_BORDER 0
#define VERT_BORDER 2
#define HORZ_GAP    2
98
#define MIN_PANE_HEIGHT 18
Alexandre Julliard's avatar
Alexandre Julliard committed
99

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

102 103
/* prototype */
static void
104
STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
105 106
static LRESULT
STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd);
107 108 109 110 111

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
112

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

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

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

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

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

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

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

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

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

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

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

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


204
static void
205
STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
Alexandre Julliard's avatar
Alexandre Julliard committed
206
{
207 208
    RECT r = part->bound;
    UINT border = BDR_SUNKENOUTER;
209 210
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    int themePart = SP_PANE;
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 234 235
    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
236
	dis.itemData = (ULONG_PTR)part->text;
237 238 239 240 241 242 243 244 245
	SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
    } else {
	if (part->hIcon) {
	   INT cy = r.bottom - r.top;

	    r.left += 2;
	    DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
	    r.left += cy;
	}
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 337 338 339 340 341 342 343 344 345 346 347 348 349
static int
STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const LPPOINT pt)
{
    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
    infoPtr->minHeight = max(height, MIN_PANE_HEIGHT);
    infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
    /* like native, don't resize the control */
Alexandre Julliard's avatar
Alexandre Julliard committed
655 656 657 658
    return TRUE;
}


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

665
    TRACE("(%d,%p)\n", count, parts);
666

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

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

694
    if (infoPtr->hwndToolTip) {
695
	UINT nTipCount;
696 697 698 699 700
	TTTOOLINFOW ti;

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

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


728
static BOOL
729
STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
730
		    LPCWSTR text, BOOL isW)
Alexandre Julliard's avatar
Alexandre Julliard committed
731
{
732
    STATUSWINDOWPART *part=NULL;
733
    BOOL changed = FALSE;
734
    INT  oldStyle;
Alexandre Julliard's avatar
Alexandre Julliard committed
735

736
    if (style & SBT_OWNERDRAW) {
Gerald Pfeifer's avatar
Gerald Pfeifer committed
737
         TRACE("part %d, text %p\n",nPart,text);
738 739
    }
    else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
740

741 742 743 744
    /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
     * window is assumed to be a simple window */

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

753 754
    if (part->style != style)
	changed = TRUE;
755

756
    oldStyle = part->style;
757
    part->style = style;
758
    if (style & SBT_OWNERDRAW) {
759 760 761
        if (!(oldStyle & SBT_OWNERDRAW))
            Free (part->text);
        else if (part->text == text)
762 763
            return TRUE;
        part->text = (LPWSTR)text;
764 765 766
    } else {
	LPWSTR ntext;

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

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

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

    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
798 799
}

Alexandre Julliard's avatar
Alexandre Julliard committed
800

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

    return 0;
}


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

    return 0;
}


837
static inline LRESULT
838
STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
839
{
840
    BOOL bOld = infoPtr->bUnicode;
841

842
    TRACE("(0x%x)\n", bUnicode);
843
    infoPtr->bUnicode = bUnicode;
844

845
    return bOld;
846
}
Alexandre Julliard's avatar
Alexandre Julliard committed
847 848


849
static BOOL
850
STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
Alexandre Julliard's avatar
Alexandre Julliard committed
851
{
Alexandre Julliard's avatar
Alexandre Julliard committed
852 853
    NMHDR  nmhdr;

854 855
    TRACE("(simple=%d)\n", simple);
    if (infoPtr->simple == simple) /* no need to change */
856 857
	return TRUE;

858
    infoPtr->simple = simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
859 860

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


static LRESULT
871
STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
Alexandre Julliard's avatar
Alexandre Julliard committed
872
{
873 874 875 876
    int	i;

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

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

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

892 893
    CloseThemeData (GetWindowTheme (infoPtr->Self));

894
    SetWindowLongPtrW(infoPtr->Self, 0, 0);
895
    Free (infoPtr);
896 897 898 899 900
    return 0;
}


static LRESULT
901
STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
902
{
903
    STATUS_INFO *infoPtr;
904
    NONCLIENTMETRICSW nclm;
905
    DWORD dwStyle;
906
    RECT rect;
907
    int	len;
Alexandre Julliard's avatar
Alexandre Julliard committed
908

909
    TRACE("\n");
910
    infoPtr = Alloc (sizeof(STATUS_INFO));
911
    if (!infoPtr) goto create_fail;
912
    SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
913

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

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

928 929 930 931
    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
932

933 934
    GetClientRect (hwnd, &rect);

Alexandre Julliard's avatar
Alexandre Julliard committed
935
    /* initialize simple case */
936 937 938 939 940
    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
941 942

    /* initialize first part */
943
    infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
944
    if (!infoPtr->parts) goto create_fail;
945 946 947 948 949
    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;
950 951
    
    OpenThemeData (hwnd, themeClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
952

953 954 955 956 957
    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
958 959
    }

960
    dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
961 962 963
    /* native seems to clear WS_BORDER, too */
    dwStyle &= ~WS_BORDER;
    SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
964

965
    infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
966

967
    if (dwStyle & SBT_TOOLTIPS) {
968
	infoPtr->hwndToolTip =
969
	    CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
970 971
			     CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			     CW_USEDEFAULT, hwnd, 0,
972
			     (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
973

974
	if (infoPtr->hwndToolTip) {
Alexandre Julliard's avatar
Alexandre Julliard committed
975 976
	    NMTOOLTIPSCREATED nmttc;

977
	    nmttc.hdr.hwndFrom = hwnd;
978
	    nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliard's avatar
Alexandre Julliard committed
979
	    nmttc.hdr.code = NM_TOOLTIPSCREATED;
980
	    nmttc.hwndToolTips = infoPtr->hwndToolTip;
Alexandre Julliard's avatar
Alexandre Julliard committed
981

982
	    SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
983
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
984 985 986
    }

    return 0;
987

988 989 990 991
create_fail:
    TRACE("    failed!\n");
    if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
    return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
992 993 994
}


995 996
/* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
 * of the first part only (usual behaviour) */
997
static INT
998
STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
Alexandre Julliard's avatar
Alexandre Julliard committed
999
{
1000
    INT len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1001

1002
    TRACE("\n");
1003
    if (!(infoPtr->parts[0].text))
Alexandre Julliard's avatar
Alexandre Julliard committed
1004
        return 0;
1005 1006

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

1008
    if (size > len) {
1009
        strcpyW (buf, infoPtr->parts[0].text);
1010
	return len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1011
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1012

1013
    return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
1014 1015 1016
}


1017
static BOOL
1018
STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
Alexandre Julliard's avatar
Alexandre Julliard committed
1019
{
1020
    if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1021 1022
	RECT  rect;
	POINT pt;
Alexandre Julliard's avatar
Alexandre Julliard committed
1023

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

1026 1027 1028
	pt.x = x;
	pt.y = y;
	ScreenToClient (infoPtr->Self, &pt);
Alexandre Julliard's avatar
Alexandre Julliard committed
1029 1030 1031 1032

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

1033
	if (PtInRect (&rect, pt))
Alexandre Julliard's avatar
Alexandre Julliard committed
1034 1035 1036
	    return HTBOTTOMRIGHT;
    }

1037
    return HTERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1038 1039 1040 1041
}


static LRESULT
1042
STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
1043
{
1044
    PAINTSTRUCT ps;
Alexandre Julliard's avatar
Alexandre Julliard committed
1045

1046
    TRACE("\n");
1047 1048 1049 1050
    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
1051 1052 1053 1054 1055 1056

    return 0;
}


static LRESULT
1057
STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
Alexandre Julliard's avatar
Alexandre Julliard committed
1058
{
1059
    infoPtr->hFont = font;
1060
    TRACE("%p\n", infoPtr->hFont);
1061 1062 1063

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

Alexandre Julliard's avatar
Alexandre Julliard committed
1067 1068 1069 1070
    return 0;
}


1071
static BOOL
1072
STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
Alexandre Julliard's avatar
Alexandre Julliard committed
1073 1074
{
    STATUSWINDOWPART *part;
Alexandre Julliard's avatar
Alexandre Julliard committed
1075
    int len;
Alexandre Julliard's avatar
Alexandre Julliard committed
1076

1077
    TRACE("\n");
1078
    if (infoPtr->numParts == 0)
Alexandre Julliard's avatar
Alexandre Julliard committed
1079
	return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1080

1081
    part = &infoPtr->parts[0];
Alexandre Julliard's avatar
Alexandre Julliard committed
1082
    /* duplicate string */
1083
    Free (part->text);
Alexandre Julliard's avatar
Alexandre Julliard committed
1084
    part->text = 0;
1085 1086 1087 1088 1089

    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
1090
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1091

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

Alexandre Julliard's avatar
Alexandre Julliard committed
1094 1095 1096
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1097

1098
static BOOL
1099
STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
Alexandre Julliard's avatar
Alexandre Julliard committed
1100
{
1101
    INT  width, x, y;
1102
    RECT parent_rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
1103

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

1107
    if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1108
	WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1109 1110
	return FALSE;
    }
1111

1112
    if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1113

1114
    /* width and height don't apply */
1115 1116 1117
    if (!GetClientRect (infoPtr->Notify, &parent_rect))
        return FALSE;

1118 1119 1120
    width = parent_rect.right - parent_rect.left;
    x = parent_rect.left;
    y = parent_rect.bottom - infoPtr->height;
1121
    MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1122 1123
    STATUSBAR_SetPartBounds (infoPtr);
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1124 1125
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1126

1127
/* update theme after a WM_THEMECHANGED message */
1128
static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1129 1130 1131 1132 1133 1134 1135 1136
{
    HTHEME theme = GetWindowTheme (infoPtr->Self);
    CloseThemeData (theme);
    OpenThemeData (infoPtr->Self, themeClass);
    return 0;
}


1137
static LRESULT
1138
STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1139 1140
{
    if (cmd == NF_REQUERY) {
1141
	INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1142
	infoPtr->bUnicode = (i == NFR_UNICODE);
1143
    }
1144
    return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1145 1146 1147
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1148
static LRESULT
1149
STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1150
{
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
    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 */
    SendMessageW(infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nm);
Alexandre Julliard's avatar
Alexandre Julliard committed
1163 1164 1165 1166 1167
    return 0;
}



1168
static LRESULT WINAPI
1169
StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
1170
{
1171
    STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1172 1173
    INT nPart = ((INT) wParam) & 0x00ff;
    LRESULT res;
1174

1175
    TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1176 1177
    if (!infoPtr && msg != WM_CREATE)
        return DefWindowProcW (hwnd, msg, wParam, lParam);
1178

Alexandre Julliard's avatar
Alexandre Julliard committed
1179
    switch (msg) {
Alexandre Julliard's avatar
Alexandre Julliard committed
1180
	case SB_GETBORDERS:
Filip Navara's avatar
Filip Navara committed
1181
	    return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1182 1183

	case SB_GETICON:
1184
	    return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1185 1186

	case SB_GETPARTS:
1187
	    return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1188 1189

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

1192
	case SB_GETTEXTA:
1193
	    return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1194

1195
	case SB_GETTEXTW:
1196
	    return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1197

1198 1199
	case SB_GETTEXTLENGTHA:
	case SB_GETTEXTLENGTHW:
1200
	    return STATUSBAR_GetTextLength (infoPtr, nPart);
Alexandre Julliard's avatar
Alexandre Julliard committed
1201

1202
	case SB_GETTIPTEXTA:
1203
	    return STATUSBAR_GetTipTextA (infoPtr,  LOWORD(wParam), (LPSTR)lParam,  HIWORD(wParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1204

1205
	case SB_GETTIPTEXTW:
1206
	    return STATUSBAR_GetTipTextW (infoPtr,  LOWORD(wParam), (LPWSTR)lParam,  HIWORD(wParam));
1207 1208

	case SB_GETUNICODEFORMAT:
1209
	    return infoPtr->bUnicode;
Alexandre Julliard's avatar
Alexandre Julliard committed
1210 1211

	case SB_ISSIMPLE:
1212
	    return infoPtr->simple;
Alexandre Julliard's avatar
Alexandre Julliard committed
1213

Filip Navara's avatar
Filip Navara committed
1214 1215 1216
	case SB_SETBORDERS:
	    return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1217
	case SB_SETBKCOLOR:
1218
	    return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1219 1220

	case SB_SETICON:
1221
	    return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1222 1223

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

1226
	case SB_SETPARTS:
1227
	    return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1228

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

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

1235
	case SB_SETTIPTEXTA:
1236
	    return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1237

1238
	case SB_SETTIPTEXTW:
1239
	    return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1240 1241

	case SB_SETUNICODEFORMAT:
1242
	    return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1243 1244

	case SB_SIMPLE:
1245
	    return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1246 1247

	case WM_CREATE:
1248
	    return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1249 1250

	case WM_DESTROY:
1251
	    return STATUSBAR_WMDestroy (infoPtr);
Alexandre Julliard's avatar
Alexandre Julliard committed
1252 1253

	case WM_GETFONT:
1254
	    return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
1255 1256

	case WM_GETTEXT:
1257
            return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1258 1259

	case WM_GETTEXTLENGTH:
1260
	    return STATUSBAR_GetTextLength (infoPtr, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
1261 1262

	case WM_LBUTTONDBLCLK:
1263
            return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1264 1265

	case WM_LBUTTONUP:
1266
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1267 1268

	case WM_MOUSEMOVE:
1269
	    return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1270 1271

	case WM_NCHITTEST:
1272 1273
	    res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
                                        (short)HIWORD(lParam));
1274 1275
	    if (res != HTERROR) return res;
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1276 1277

	case WM_NCLBUTTONUP:
1278
	case WM_NCLBUTTONDOWN:
1279
    	    PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1280
	    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1281

1282 1283
	case WM_NOTIFYFORMAT:
	    return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1284

1285
	case WM_PRINTCLIENT:
Alexandre Julliard's avatar
Alexandre Julliard committed
1286
	case WM_PAINT:
1287
	    return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1288 1289

	case WM_RBUTTONDBLCLK:
1290
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1291 1292

	case WM_RBUTTONUP:
1293
	    return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1294 1295

	case WM_SETFONT:
1296
	    return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
Alexandre Julliard's avatar
Alexandre Julliard committed
1297 1298

	case WM_SETTEXT:
1299 1300
	    return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
1301
	case WM_SIZE:
1302 1303
	    if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
            return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1304

1305 1306 1307
        case WM_THEMECHANGED:
            return theme_changed (infoPtr);

Alexandre Julliard's avatar
Alexandre Julliard committed
1308
	default:
1309
	    if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
1310
		ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1311
		     msg, wParam, lParam);
1312
	    return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1313 1314 1315 1316
    }
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1317
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1318
 * STATUS_Register [Internal]
Alexandre Julliard's avatar
Alexandre Julliard committed
1319 1320 1321
 *
 * Registers the status window class.
 */
1322

1323
void
1324
STATUS_Register (void)
Alexandre Julliard's avatar
Alexandre Julliard committed
1325
{
1326
    WNDCLASSW wndClass;
Alexandre Julliard's avatar
Alexandre Julliard committed
1327

1328
    ZeroMemory (&wndClass, sizeof(WNDCLASSW));
Alexandre Julliard's avatar
Alexandre Julliard committed
1329
    wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1330
    wndClass.lpfnWndProc   = StatusWindowProc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1331
    wndClass.cbClsExtra    = 0;
1332
    wndClass.cbWndExtra    = sizeof(STATUS_INFO *);
1333
    wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1334
    wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1335
    wndClass.lpszClassName = STATUSCLASSNAMEW;
1336

1337
    RegisterClassW (&wndClass);
Alexandre Julliard's avatar
Alexandre Julliard committed
1338
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1339

1340 1341 1342 1343 1344 1345 1346

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

1347
void
1348
STATUS_Unregister (void)
1349
{
1350
    UnregisterClassW (STATUSCLASSNAMEW, NULL);
1351
}