static.c 25.7 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4 5
/*
 * Static control
 *
 * Copyright  David W. Metcalfe, 1993
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25 26 27 28
 *
 * NOTES
 *
 * This code was audited for completeness against the documented features
 * of Comctl32.dll version 6.0 on Oct. 4, 2004, 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.
 *
29 30 31 32 33 34 35 36 37 38 39
 * Notes:
 *   - Windows XP introduced new behavior: The background of centered
 *     icons and bitmaps is painted differently. This is only done if
 *     a manifest is present.
 *     Because it has not yet been decided how to implement the two
 *     different modes in Wine, only the Windows XP mode is implemented.
 *   - Controls with SS_SIMPLE but without SS_NOPREFIX:
 *     The text should not be changed. Windows doesn't clear the
 *     client rectangle, so the new text must be larger than the old one.
 *   - The SS_RIGHTJUST style is currently not implemented by Windows
 *     (or it does something different than documented).
40
 *
41 42
 * TODO:
 *   - Animated cursors
Alexandre Julliard's avatar
Alexandre Julliard committed
43
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
44

45 46
#include <stdarg.h>

47
#include "windef.h"
48
#include "winbase.h"
49
#include "wingdi.h"
50
#include "controls.h"
51
#include "user_private.h"
52
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
53

54
WINE_DEFAULT_DEBUG_CHANNEL(static);
55

56 57 58 59 60
static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
61
static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
62
static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
Alexandre Julliard's avatar
Alexandre Julliard committed
63

64
static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
Alexandre Julliard's avatar
Alexandre Julliard committed
65

66 67 68 69
/* offsets for GetWindowLong for static private information */
#define HFONT_GWL_OFFSET    0
#define HICON_GWL_OFFSET    (sizeof(HFONT))
#define STATIC_EXTRA_BYTES  (HICON_GWL_OFFSET + sizeof(HICON))
Alexandre Julliard's avatar
Alexandre Julliard committed
70

71
typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
Alexandre Julliard's avatar
Alexandre Julliard committed
72

73
static const pfPaint staticPaintFunc[SS_TYPEMASK+1] =
Alexandre Julliard's avatar
Alexandre Julliard committed
74
{
Alexandre Julliard's avatar
Alexandre Julliard committed
75 76 77 78 79 80 81 82 83 84
    STATIC_PaintTextfn,      /* SS_LEFT */
    STATIC_PaintTextfn,      /* SS_CENTER */
    STATIC_PaintTextfn,      /* SS_RIGHT */
    STATIC_PaintIconfn,      /* SS_ICON */
    STATIC_PaintRectfn,      /* SS_BLACKRECT */
    STATIC_PaintRectfn,      /* SS_GRAYRECT */
    STATIC_PaintRectfn,      /* SS_WHITERECT */
    STATIC_PaintRectfn,      /* SS_BLACKFRAME */
    STATIC_PaintRectfn,      /* SS_GRAYFRAME */
    STATIC_PaintRectfn,      /* SS_WHITEFRAME */
85
    NULL,                    /* SS_USERITEM */
Alexandre Julliard's avatar
Alexandre Julliard committed
86
    STATIC_PaintTextfn,      /* SS_SIMPLE */
Alexandre Julliard's avatar
Alexandre Julliard committed
87
    STATIC_PaintTextfn,      /* SS_LEFTNOWORDWRAP */
88
    STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
Alexandre Julliard's avatar
Alexandre Julliard committed
89
    STATIC_PaintBitmapfn,    /* SS_BITMAP */
90
    STATIC_PaintEnhMetafn,   /* SS_ENHMETAFILE */
91
    STATIC_PaintEtchedfn,    /* SS_ETCHEDHORZ */
Alexandre Julliard's avatar
Alexandre Julliard committed
92 93
    STATIC_PaintEtchedfn,    /* SS_ETCHEDVERT */
    STATIC_PaintEtchedfn,    /* SS_ETCHEDFRAME */
Alexandre Julliard's avatar
Alexandre Julliard committed
94 95 96
};


97 98 99
/*********************************************************************
 * static class descriptor
 */
100
static const WCHAR staticW[] = {'S','t','a','t','i','c',0};
101 102
const struct builtin_class_descr STATIC_builtin_class =
{
103
    staticW,             /* name */
104
    CS_DBLCLKS | CS_PARENTDC, /* style  */
105
    WINPROC_STATIC,      /* proc */
106
    STATIC_EXTRA_BYTES,  /* extra */
107
    IDC_ARROW,           /* cursor */
108 109 110
    0                    /* brush */
};

Alexandre Julliard's avatar
Alexandre Julliard committed
111 112 113 114 115
/***********************************************************************
 *           STATIC_SetIcon
 *
 * Set the icon for an SS_ICON control.
 */
116
static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
117
{
118
    HICON prevIcon;
119
    SIZE size;
120

121
    if ((style & SS_TYPEMASK) != SS_ICON) return 0;
122 123 124
    if (hicon && !get_icon_size( hicon, &size ))
    {
        WARN("hicon != 0, but invalid\n");
125
        return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
126
    }
127
    prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
128
    if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
Alexandre Julliard's avatar
Alexandre Julliard committed
129
    {
130 131 132 133 134 135 136 137 138 139 140
        /* Windows currently doesn't implement SS_RIGHTJUST */
        /*
        if ((style & SS_RIGHTJUST) != 0)
        {
            RECT wr;
            GetWindowRect(hwnd, &wr);
            SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
                          info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
        }
        else */
        {
141
            SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
142
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
143
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
144
    return prevIcon;
Alexandre Julliard's avatar
Alexandre Julliard committed
145 146
}

Alexandre Julliard's avatar
Alexandre Julliard committed
147 148 149 150 151
/***********************************************************************
 *           STATIC_SetBitmap
 *
 * Set the bitmap for an SS_BITMAP control.
 */
152
static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
153
{
154
    HBITMAP hOldBitmap;
Alexandre Julliard's avatar
Alexandre Julliard committed
155

156
    if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
157
    if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
158 159
        WARN("hBitmap != 0, but it's not a bitmap\n");
        return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
160
    }
161
    hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
162
    if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
Alexandre Julliard's avatar
Alexandre Julliard committed
163
    {
164
        BITMAP bm;
165
        GetObjectW(hBitmap, sizeof(bm), &bm);
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        /* Windows currently doesn't implement SS_RIGHTJUST */
        /*
        if ((style & SS_RIGHTJUST) != 0)
        {
            RECT wr;
            GetWindowRect(hwnd, &wr);
            SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
                          bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
        }
        else */
        {
            SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
                          SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
        }
	
Alexandre Julliard's avatar
Alexandre Julliard committed
181
    }
182
    return hOldBitmap;
Alexandre Julliard's avatar
Alexandre Julliard committed
183 184
}

185 186 187 188 189 190 191 192 193
/***********************************************************************
 *           STATIC_SetEnhMetaFile
 *
 * Set the enhanced metafile for an SS_ENHMETAFILE control.
 */
static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
{
    if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
    if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
194
        WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
195 196 197 198 199
        return 0;
    }
    return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
}

200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
/***********************************************************************
 *           STATIC_GetImage
 *
 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
 */
static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
{
    switch(style & SS_TYPEMASK)
    {
        case SS_ICON:
            if ((wParam != IMAGE_ICON) &&
                (wParam != IMAGE_CURSOR)) return NULL;
            break;
        case SS_BITMAP:
            if (wParam != IMAGE_BITMAP) return NULL;
            break;
        case SS_ENHMETAFILE:
            if (wParam != IMAGE_ENHMETAFILE) return NULL;
            break;
        default:
            return NULL;
    }
    return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
}

Alexandre Julliard's avatar
Alexandre Julliard committed
226
/***********************************************************************
227
 *           STATIC_LoadIconA
Alexandre Julliard's avatar
Alexandre Julliard committed
228 229 230
 *
 * Load the icon for an SS_ICON control.
 */
231
static HICON STATIC_LoadIconA( HINSTANCE hInstance, LPCSTR name, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
232
{
233
    HICON hicon = 0;
234 235

    if (hInstance && ((ULONG_PTR)hInstance >> 16))
236
    {
237 238 239 240 241 242 243
        if ((style & SS_REALSIZEIMAGE) != 0)
            hicon = LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
        else
        {
            hicon = LoadIconA( hInstance, name );
            if (!hicon) hicon = LoadCursorA( hInstance, name );
        }
244
    }
245 246 247 248 249
    if (!hicon) hicon = LoadIconA( 0, name );
    /* Windows doesn't try to load a standard cursor,
       probably because most IDs for standard cursors conflict
       with the IDs for standard icons anyway */
    return hicon;
Alexandre Julliard's avatar
Alexandre Julliard committed
250 251
}

Alexandre Julliard's avatar
Alexandre Julliard committed
252
/***********************************************************************
253 254 255 256
 *           STATIC_LoadIconW
 *
 * Load the icon for an SS_ICON control.
 */
257
static HICON STATIC_LoadIconW( HINSTANCE hInstance, LPCWSTR name, DWORD style )
258
{
259
    HICON hicon = 0;
260 261

    if (hInstance && ((ULONG_PTR)hInstance >> 16))
262
    {
263 264 265 266 267 268 269
        if ((style & SS_REALSIZEIMAGE) != 0)
            hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
        else
        {
            hicon = LoadIconW( hInstance, name );
            if (!hicon) hicon = LoadCursorW( hInstance, name );
        }
270
    }
271 272 273 274 275
    if (!hicon) hicon = LoadIconW( 0, name );
    /* Windows doesn't try to load a standard cursor,
       probably because most IDs for standard cursors conflict
       with the IDs for standard icons anyway */
    return hicon;
276
}
Alexandre Julliard's avatar
Alexandre Julliard committed
277

278 279 280 281 282 283 284 285 286 287 288 289 290 291
/***********************************************************************
 *           STATIC_TryPaintFcn
 *
 * Try to immediately paint the control.
 */
static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
{
    LONG style = full_style & SS_TYPEMASK;
    RECT rc;

    GetClientRect( hwnd, &rc );
    if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
    {
	HDC hdc;
292
        HRGN hrgn;
293

294
	hdc = GetDC( hwnd );
295
        hrgn = set_control_clipping( hdc, &rc );
296
	(staticPaintFunc[style])( hwnd, hdc, full_style );
297 298
        SelectClipRgn( hdc, hrgn );
        if (hrgn) DeleteObject( hrgn );
299 300 301 302
	ReleaseDC( hwnd, hdc );
    }
}

303 304
static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
{
305 306 307 308 309
    HBRUSH hBrush;
    HWND parent = GetParent(hwnd);

    if (!parent) parent = hwnd;
    hBrush = (HBRUSH) SendMessageW( parent,
310 311 312 313 314
                    WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
    if (!hBrush) /* did the app forget to call DefWindowProc ? */
    {
        /* FIXME: DefWindowProc should return different colors if a
                  manifest is present */
315
        hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
316 317 318 319 320
                                        (WPARAM)hdc, (LPARAM)hwnd);
    }
    return hBrush;
}

321
static VOID STATIC_InitColours(void)
322 323 324 325 326 327
{
    color_3ddkshadow  = GetSysColor(COLOR_3DDKSHADOW);
    color_3dshadow    = GetSysColor(COLOR_3DSHADOW);
    color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
}

328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
/***********************************************************************
 *           hasTextStyle
 *
 * Tests if the control displays text.
 */
static BOOL hasTextStyle( DWORD style )
{
    switch(style & SS_TYPEMASK)
    {
        case SS_SIMPLE:
        case SS_LEFT:
        case SS_LEFTNOWORDWRAP:
        case SS_CENTER:
        case SS_RIGHT:
        case SS_OWNERDRAW:
            return TRUE;
    }
    
    return FALSE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
349
/***********************************************************************
350
 *           StaticWndProc_common
Alexandre Julliard's avatar
Alexandre Julliard committed
351
 */
352
LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
Alexandre Julliard's avatar
Alexandre Julliard committed
353
{
Alexandre Julliard's avatar
Alexandre Julliard committed
354
    LRESULT lResult = 0;
355
    LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
356
    LONG style = full_style & SS_TYPEMASK;
Alexandre Julliard's avatar
Alexandre Julliard committed
357

358 359
    if (!IsWindow( hwnd )) return 0;

Alexandre Julliard's avatar
Alexandre Julliard committed
360 361
    switch (uMsg)
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
362
    case WM_CREATE:
Alexandre Julliard's avatar
Alexandre Julliard committed
363
        if (style < 0L || style > SS_TYPEMASK)
Alexandre Julliard's avatar
Alexandre Julliard committed
364
        {
365
            ERR("Unknown style 0x%02x\n", style );
366
            return -1;
Alexandre Julliard's avatar
Alexandre Julliard committed
367
        }
368
        STATIC_InitColours();
Alexandre Julliard's avatar
Alexandre Julliard committed
369 370 371
        break;

    case WM_NCDESTROY:
372 373 374 375
        if (style == SS_ICON) {
/*
 * FIXME
 *           DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
376
 *
377 378 379 380
 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
 * had already been loaded by the application the last thing we want to do is
 * GlobalFree16 the handle.
 */
381 382 383 384
            break;
        }
        else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
                              DefWindowProcA(hwnd, uMsg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
385

386 387 388 389
    case WM_ERASEBKGND:
        /* do all painting in WM_PAINT like Windows does */
        return 1;

390
    case WM_PRINTCLIENT:
Alexandre Julliard's avatar
Alexandre Julliard committed
391 392
    case WM_PAINT:
        {
393
            PAINTSTRUCT ps;
394
            RECT rect;
395
            HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
396
            GetClientRect( hwnd, &rect );
Alexandre Julliard's avatar
Alexandre Julliard committed
397
            if (staticPaintFunc[style])
398
            {
399
                HRGN hrgn = set_control_clipping( hdc, &rect );
400
                (staticPaintFunc[style])( hwnd, hdc, full_style );
401 402
                SelectClipRgn( hdc, hrgn );
                if (hrgn) DeleteObject( hrgn );
403
            }
404
            if (!wParam) EndPaint(hwnd, &ps);
Alexandre Julliard's avatar
Alexandre Julliard committed
405 406 407 408
        }
        break;

    case WM_ENABLE:
409 410 411 412 413 414 415 416 417 418 419
        STATIC_TryPaintFcn( hwnd, full_style );
        if (full_style & SS_NOTIFY) {
            if (wParam) {
                SendMessageW( GetParent(hwnd), WM_COMMAND,
                              MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
            }
            else {
                SendMessageW( GetParent(hwnd), WM_COMMAND,
                              MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
            }
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
420 421 422
        break;

    case WM_SYSCOLORCHANGE:
423
        STATIC_InitColours();
424
        STATIC_TryPaintFcn( hwnd, full_style );
Alexandre Julliard's avatar
Alexandre Julliard committed
425 426
        break;

427
    case WM_NCCREATE:
428
        {
429 430
            CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;

431 432 433 434 435 436 437 438
            if (full_style & SS_SUNKEN)
                SetWindowLongW( hwnd, GWL_EXSTYLE,
                                GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );

            switch (style) {
            case SS_ICON:
                {
                    HICON hIcon;
439 440
                    if (unicode || IS_INTRESOURCE(cs->lpszName))
                       hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName, full_style);
441
                    else
442
                       hIcon = STATIC_LoadIconA(cs->hInstance, (LPCSTR)cs->lpszName, full_style);
443 444 445 446
                    STATIC_SetIcon(hwnd, hIcon, full_style);
                }
                break;
            case SS_BITMAP:
447
                if ((ULONG_PTR)cs->hInstance >> 16)
448 449
                {
                    HBITMAP hBitmap;
450 451
                    if (unicode || IS_INTRESOURCE(cs->lpszName))
                        hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName);
452
                    else
453
                        hBitmap = LoadBitmapA(cs->hInstance, (LPCSTR)cs->lpszName);
454 455 456 457 458 459 460 461 462 463
                    STATIC_SetBitmap(hwnd, hBitmap, full_style);
                }
                break;
            }
            /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
               the enhanced metafile that was specified as the window text. */
        }
        return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
                         DefWindowProcA(hwnd, uMsg, wParam, lParam);

Alexandre Julliard's avatar
Alexandre Julliard committed
464
    case WM_SETTEXT:
465
        if (hasTextStyle( full_style ))
466 467 468
        {
	    if (HIWORD(lParam))
	    {
469 470 471 472 473
	        if(unicode)
		     lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
                else
                    lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
	        STATIC_TryPaintFcn( hwnd, full_style );
474 475
	    }
	}
476
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
477 478

    case WM_SETFONT:
479 480 481 482
        if (hasTextStyle( full_style ))
        {
            SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
            if (LOWORD(lParam))
483
                RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
484
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
485
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
486

Alexandre Julliard's avatar
Alexandre Julliard committed
487
    case WM_GETFONT:
488
        return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
Alexandre Julliard's avatar
Alexandre Julliard committed
489

Alexandre Julliard's avatar
Alexandre Julliard committed
490
    case WM_NCHITTEST:
491 492
        if (full_style & SS_NOTIFY)
           return HTCLIENT;
493
        else
494
           return HTTRANSPARENT;
Alexandre Julliard's avatar
Alexandre Julliard committed
495

Alexandre Julliard's avatar
Alexandre Julliard committed
496
    case WM_GETDLGCODE:
497
        return DLGC_STATIC;
Alexandre Julliard's avatar
Alexandre Julliard committed
498

499 500 501 502
    case WM_LBUTTONDOWN:
    case WM_NCLBUTTONDOWN:
        if (full_style & SS_NOTIFY)
            SendMessageW( GetParent(hwnd), WM_COMMAND,
503
                          MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
504 505 506 507 508 509
        return 0;

    case WM_LBUTTONDBLCLK:
    case WM_NCLBUTTONDBLCLK:
        if (full_style & SS_NOTIFY)
            SendMessageW( GetParent(hwnd), WM_COMMAND,
510
                          MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
511 512
        return 0;

Alexandre Julliard's avatar
Alexandre Julliard committed
513
    case STM_GETIMAGE:
514
        return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
515

516
    case STM_GETICON:
517
        return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
Alexandre Julliard's avatar
Alexandre Julliard committed
518

Alexandre Julliard's avatar
Alexandre Julliard committed
519
    case STM_SETIMAGE:
520 521
        switch(wParam) {
	case IMAGE_BITMAP:
522
	    lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
523
	    break;
524
	case IMAGE_ENHMETAFILE:
525
	    lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
526
	    break;
527
	case IMAGE_ICON:
528
	case IMAGE_CURSOR:
529
	    lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
530 531
	    break;
	default:
532
	    FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
533 534
	    break;
	}
535
        STATIC_TryPaintFcn( hwnd, full_style );
Alexandre Julliard's avatar
Alexandre Julliard committed
536
	break;
Alexandre Julliard's avatar
Alexandre Julliard committed
537

538
    case STM_SETICON:
539
        lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
540
        STATIC_TryPaintFcn( hwnd, full_style );
Alexandre Julliard's avatar
Alexandre Julliard committed
541
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
542

Alexandre Julliard's avatar
Alexandre Julliard committed
543
    default:
544 545
        return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
                         DefWindowProcA(hwnd, uMsg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
546
    }
547 548 549
    return lResult;
}

550
static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
551 552
{
  DRAWITEMSTRUCT dis;
553
  HFONT font, oldFont = NULL;
554
  UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
555 556

  dis.CtlType    = ODT_STATIC;
557
  dis.CtlID      = id;
558 559
  dis.itemID     = 0;
  dis.itemAction = ODA_DRAWENTIRE;
560
  dis.itemState  = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
561
  dis.hwndItem   = hwnd;
562 563
  dis.hDC        = hdc;
  dis.itemData   = 0;
564
  GetClientRect( hwnd, &dis.rcItem );
565

566 567
  font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
  if (font) oldFont = SelectObject( hdc, font );
568
  SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
569
  SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
570
  if (font) SelectObject( hdc, oldFont );
571
}
Alexandre Julliard's avatar
Alexandre Julliard committed
572

573
static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
574
{
575 576
    RECT rc;
    HBRUSH hBrush;
577
    HFONT hFont, hOldFont = NULL;
578
    UINT format;
579
    INT len, buf_size;
580
    WCHAR *text;
Alexandre Julliard's avatar
Alexandre Julliard committed
581

582
    GetClientRect( hwnd, &rc);
Alexandre Julliard's avatar
Alexandre Julliard committed
583

Alexandre Julliard's avatar
Alexandre Julliard committed
584
    switch (style & SS_TYPEMASK)
Alexandre Julliard's avatar
Alexandre Julliard committed
585 586
    {
    case SS_LEFT:
587
	format = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
Alexandre Julliard's avatar
Alexandre Julliard committed
588 589 590
	break;

    case SS_CENTER:
591
	format = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
Alexandre Julliard's avatar
Alexandre Julliard committed
592 593 594
	break;

    case SS_RIGHT:
595
	format = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
Alexandre Julliard's avatar
Alexandre Julliard committed
596 597 598
	break;

    case SS_SIMPLE:
599
        format = DT_LEFT | DT_SINGLELINE;
Alexandre Julliard's avatar
Alexandre Julliard committed
600 601 602
	break;

    case SS_LEFTNOWORDWRAP:
603
        format = DT_LEFT | DT_EXPANDTABS;
Alexandre Julliard's avatar
Alexandre Julliard committed
604
	break;
Alexandre Julliard's avatar
Alexandre Julliard committed
605 606 607

    default:
        return;
Alexandre Julliard's avatar
Alexandre Julliard committed
608 609
    }

610
    if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
611
        format = DT_RIGHT | (format & ~(DT_LEFT | DT_CENTER));
612

Alexandre Julliard's avatar
Alexandre Julliard committed
613
    if (style & SS_NOPREFIX)
614
        format |= DT_NOPREFIX;
615

616 617 618
    if ((style & SS_TYPEMASK) != SS_SIMPLE)
    {
        if (style & SS_CENTERIMAGE)
619
            format |= DT_SINGLELINE | DT_VCENTER;
620
        if (style & SS_EDITCONTROL)
621
            format |= DT_EDITCONTROL;
622
        if (style & SS_ENDELLIPSIS)
623
            format |= DT_SINGLELINE | DT_END_ELLIPSIS;
624
        if (style & SS_PATHELLIPSIS)
625
            format |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
626
        if (style & SS_WORDELLIPSIS)
627
            format |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
628
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
629

630
    if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
631
        hOldFont = SelectObject( hdc, hFont );
632

633 634 635
    /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
                           brush is not used */
    hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
636

637
    if ((style & SS_TYPEMASK) != SS_SIMPLE)
638
    {
639
        FillRect( hdc, &rc, hBrush );
640
        if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
641
    }
642

643
    buf_size = 256;
644 645
    if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
        goto no_TextOut;
646 647 648 649

    while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
    {
        buf_size *= 2;
650 651
        if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
            goto no_TextOut;
652 653
    }

654 655
    if (!len) goto no_TextOut;

656 657 658 659 660 661 662 663 664 665
    if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
    {
        /* Windows uses the faster ExtTextOut() to draw the text and
           to paint the whole client rectangle with the text background
           color. Reference: "Static Controls" by Kyle Marsh, 1992 */
        ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
                     &rc, text, len, NULL );
    }
    else
    {
666
        DrawTextW( hdc, text, -1, &rc, format );
667
    }
668

669
no_TextOut:
670
    HeapFree( GetProcessHeap(), 0, text );
671

672 673
    if (hFont)
        SelectObject( hdc, hOldFont );
Alexandre Julliard's avatar
Alexandre Julliard committed
674 675
}

676
static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
677
{
678 679
    RECT rc;
    HBRUSH hBrush;
Alexandre Julliard's avatar
Alexandre Julliard committed
680

681
    GetClientRect( hwnd, &rc);
682

683
    /* FIXME: send WM_CTLCOLORSTATIC */
684
    switch (style & SS_TYPEMASK)
Alexandre Julliard's avatar
Alexandre Julliard committed
685 686
    {
    case SS_BLACKRECT:
687
	hBrush = CreateSolidBrush(color_3ddkshadow);
688
        FillRect( hdc, &rc, hBrush );
Alexandre Julliard's avatar
Alexandre Julliard committed
689 690
	break;
    case SS_GRAYRECT:
691
	hBrush = CreateSolidBrush(color_3dshadow);
692
        FillRect( hdc, &rc, hBrush );
Alexandre Julliard's avatar
Alexandre Julliard committed
693 694
	break;
    case SS_WHITERECT:
695
	hBrush = CreateSolidBrush(color_3dhighlight);
696
        FillRect( hdc, &rc, hBrush );
Alexandre Julliard's avatar
Alexandre Julliard committed
697 698
	break;
    case SS_BLACKFRAME:
699
	hBrush = CreateSolidBrush(color_3ddkshadow);
700
        FrameRect( hdc, &rc, hBrush );
Alexandre Julliard's avatar
Alexandre Julliard committed
701 702
	break;
    case SS_GRAYFRAME:
703
	hBrush = CreateSolidBrush(color_3dshadow);
704
        FrameRect( hdc, &rc, hBrush );
Alexandre Julliard's avatar
Alexandre Julliard committed
705 706
	break;
    case SS_WHITEFRAME:
707
	hBrush = CreateSolidBrush(color_3dhighlight);
708
        FrameRect( hdc, &rc, hBrush );
Alexandre Julliard's avatar
Alexandre Julliard committed
709
	break;
Alexandre Julliard's avatar
Alexandre Julliard committed
710 711
    default:
        return;
Alexandre Julliard's avatar
Alexandre Julliard committed
712
    }
713
    DeleteObject( hBrush );
Alexandre Julliard's avatar
Alexandre Julliard committed
714 715 716
}


717
static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
718
{
719
    RECT rc, iconRect;
720
    HBRUSH hbrush;
721
    HICON hIcon;
722
    SIZE size;
Alexandre Julliard's avatar
Alexandre Julliard committed
723

724
    GetClientRect( hwnd, &rc );
725
    hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
726
    hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
727
    if (!hIcon || !get_icon_size( hIcon, &size ))
728
    {
729
        FillRect(hdc, &rc, hbrush);
730 731 732
    }
    else
    {
733 734
        if (style & SS_CENTERIMAGE)
        {
735 736 737 738
            iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
            iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
            iconRect.right = iconRect.left + size.cx;
            iconRect.bottom = iconRect.top + size.cy;
739
        }
740 741
        else
            iconRect = rc;
742
        FillRect( hdc, &rc, hbrush );
743 744
        DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
                    iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
745
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
746
}
Alexandre Julliard's avatar
Alexandre Julliard committed
747

748
static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
749
{
750
    HDC hMemDC;
751
    HBITMAP hBitmap, oldbitmap;
752
    HBRUSH hbrush;
Alexandre Julliard's avatar
Alexandre Julliard committed
753

754
    /* message is still sent, even if the returned brush is not used */
755
    hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
756

757 758 759
    if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
         && (GetObjectType(hBitmap) == OBJ_BITMAP)
         && (hMemDC = CreateCompatibleDC( hdc )))
760
    {
761
        BITMAP bm;
762 763 764 765 766
        RECT rcClient;
        LOGBRUSH brush;

        GetObjectW(hBitmap, sizeof(bm), &bm);
        oldbitmap = SelectObject(hMemDC, hBitmap);
Alexandre Julliard's avatar
Alexandre Julliard committed
767

768 769 770 771 772 773 774 775
        /* Set the background color for monochrome bitmaps
           to the color of the background brush */
        if (GetObjectW( hbrush, sizeof(brush), &brush ))
        {
            if (brush.lbStyle == BS_SOLID)
                SetBkColor(hdc, brush.lbColor);
        }
        GetClientRect(hwnd, &rcClient);
776 777
        if (style & SS_CENTERIMAGE)
        {
778
            INT x, y;
779 780
            x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
            y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
781 782 783
            FillRect( hdc, &rcClient, hbrush );
            BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
                   SRCCOPY);
784 785 786
        }
        else
        {
787 788 789
            StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
                       rcClient.bottom - rcClient.top, hMemDC,
                       0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
790
        }
791 792 793
        SelectObject(hMemDC, oldbitmap);
        DeleteDC(hMemDC);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
794
}
Alexandre Julliard's avatar
Alexandre Julliard committed
795 796


797 798 799
static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
{
    HENHMETAFILE hEnhMetaFile;
800 801 802 803 804 805
    RECT rc;
    HBRUSH hbrush;
    
    GetClientRect(hwnd, &rc);
    hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
    FillRect(hdc, &rc, hbrush);
806 807
    if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
    {
808 809 810 811
        /* The control's current font is not selected into the
           device context! */
        if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
            PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
812 813 814 815
    }
}


816
static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard's avatar
Alexandre Julliard committed
817
{
818
    RECT rc;
Alexandre Julliard's avatar
Alexandre Julliard committed
819

820
    /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
821 822
    GetClientRect( hwnd, &rc );
    switch (style & SS_TYPEMASK)
Alexandre Julliard's avatar
Alexandre Julliard committed
823 824
    {
	case SS_ETCHEDHORZ:
825
	    DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
Alexandre Julliard's avatar
Alexandre Julliard committed
826 827
	    break;
	case SS_ETCHEDVERT:
828
	    DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
Alexandre Julliard's avatar
Alexandre Julliard committed
829 830
	    break;
	case SS_ETCHEDFRAME:
831
	    DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
Alexandre Julliard's avatar
Alexandre Julliard committed
832 833 834
	    break;
    }
}