blob: 188e1e07cc7776fd3592522a465aa21f95cd82da [file] [log] [blame]
Alexandre Julliard0e607781993-11-03 19:23:37 +00001/*
2 * Static control
3 *
4 * Copyright David W. Metcalfe, 1993
5 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00006 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard8664b891996-04-05 14:58:24 +000019 */
Alexandre Julliard0e607781993-11-03 19:23:37 +000020
Jeremy Whited3e22d92000-02-10 19:03:02 +000021#include "windef.h"
22#include "wingdi.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000023#include "wine/winuser16.h"
Alexandre Julliard0ca051e2002-10-17 16:43:42 +000024#include "wownt32.h"
Alexandre Julliard491502b1997-11-01 19:08:16 +000025#include "cursoricon.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000026#include "controls.h"
Alexandre Julliarda41b2cf2001-01-15 20:12:55 +000027#include "user.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000028#include "wine/debug.h"
Alexandre Julliard0e607781993-11-03 19:23:37 +000029
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000030WINE_DEFAULT_DEBUG_CHANNEL(static);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000031
Alexandre Julliardde424282001-08-10 22:51:42 +000032static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
33static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
34static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
35static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
36static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
37static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
Alexandre Julliard91222da2000-12-10 23:01:33 +000038static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +000039static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
Alexandre Julliard0e607781993-11-03 19:23:37 +000040
Alexandre Julliardaca05781994-10-17 18:12:41 +000041static COLORREF color_windowframe, color_background, color_window;
Alexandre Julliard0e607781993-11-03 19:23:37 +000042
Alexandre Julliardde424282001-08-10 22:51:42 +000043/* offsets for GetWindowLong for static private information */
44#define HFONT_GWL_OFFSET 0
45#define HICON_GWL_OFFSET (sizeof(HFONT))
46#define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
Alexandre Julliard0e607781993-11-03 19:23:37 +000047
Alexandre Julliardde424282001-08-10 22:51:42 +000048typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
Alexandre Julliardaca05781994-10-17 18:12:41 +000049
Alexandre Julliard491502b1997-11-01 19:08:16 +000050static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
Alexandre Julliard0e607781993-11-03 19:23:37 +000051{
Alexandre Julliard8664b891996-04-05 14:58:24 +000052 STATIC_PaintTextfn, /* SS_LEFT */
53 STATIC_PaintTextfn, /* SS_CENTER */
54 STATIC_PaintTextfn, /* SS_RIGHT */
55 STATIC_PaintIconfn, /* SS_ICON */
56 STATIC_PaintRectfn, /* SS_BLACKRECT */
57 STATIC_PaintRectfn, /* SS_GRAYRECT */
58 STATIC_PaintRectfn, /* SS_WHITERECT */
59 STATIC_PaintRectfn, /* SS_BLACKFRAME */
60 STATIC_PaintRectfn, /* SS_GRAYFRAME */
61 STATIC_PaintRectfn, /* SS_WHITEFRAME */
Alexandre Julliardaca05781994-10-17 18:12:41 +000062 NULL, /* Not defined */
Alexandre Julliard8664b891996-04-05 14:58:24 +000063 STATIC_PaintTextfn, /* SS_SIMPLE */
Alexandre Julliard491502b1997-11-01 19:08:16 +000064 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
Luc Tourangeaue84b6782000-02-07 16:01:04 +000065 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
Alexandre Julliard491502b1997-11-01 19:08:16 +000066 STATIC_PaintBitmapfn, /* SS_BITMAP */
67 NULL, /* SS_ENHMETAFILE */
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +000068 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
69 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
70 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
Alexandre Julliard0e607781993-11-03 19:23:37 +000071};
72
73
Alexandre Julliard91222da2000-12-10 23:01:33 +000074/*********************************************************************
75 * static class descriptor
76 */
77const struct builtin_class_descr STATIC_builtin_class =
78{
79 "Static", /* name */
80 CS_GLOBALCLASS | CS_DBLCLKS | CS_PARENTDC, /* style */
81 StaticWndProcA, /* procA */
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +000082 StaticWndProcW, /* procW */
Alexandre Julliardde424282001-08-10 22:51:42 +000083 STATIC_EXTRA_BYTES, /* extra */
Alexandre Julliard91222da2000-12-10 23:01:33 +000084 IDC_ARROWA, /* cursor */
85 0 /* brush */
86};
87
88
Alexandre Julliardaca05781994-10-17 18:12:41 +000089/***********************************************************************
90 * STATIC_SetIcon
91 *
92 * Set the icon for an SS_ICON control.
93 */
Alexandre Julliardde424282001-08-10 22:51:42 +000094static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
Alexandre Julliardaca05781994-10-17 18:12:41 +000095{
Alexandre Julliardde424282001-08-10 22:51:42 +000096 HICON prevIcon;
Michael Stefaniucbc54d782002-10-10 21:22:09 +000097 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16(HICON_16(hicon)):NULL;
Alexandre Julliardaca05781994-10-17 18:12:41 +000098
Alexandre Julliardde424282001-08-10 22:51:42 +000099 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000100 if (hicon && !info) {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000101 ERR("huh? hicon!=0, but info=0???\n");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000102 return 0;
103 }
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000104 prevIcon = (HICON)SetWindowLongA( hwnd, HICON_GWL_OFFSET, (LONG)hicon );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000105 if (hicon)
106 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000107 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
Alexandre Julliard01d63461997-01-20 19:43:45 +0000108 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000109 GlobalUnlock16(HICON_16(hicon));
Alexandre Julliardaca05781994-10-17 18:12:41 +0000110 }
Alexandre Julliard7d654eb1996-02-25 11:36:22 +0000111 return prevIcon;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000112}
113
Alexandre Julliard491502b1997-11-01 19:08:16 +0000114/***********************************************************************
115 * STATIC_SetBitmap
116 *
117 * Set the bitmap for an SS_BITMAP control.
118 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000119static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
Alexandre Julliard491502b1997-11-01 19:08:16 +0000120{
Alexandre Julliardde424282001-08-10 22:51:42 +0000121 HBITMAP hOldBitmap;
Alexandre Julliard491502b1997-11-01 19:08:16 +0000122
Alexandre Julliardde424282001-08-10 22:51:42 +0000123 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000124 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
125 ERR("huh? hBitmap!=0, but not bitmap\n");
Alexandre Julliard491502b1997-11-01 19:08:16 +0000126 return 0;
127 }
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000128 hOldBitmap = (HBITMAP)SetWindowLongA( hwnd, HICON_GWL_OFFSET, (LONG)hBitmap );
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000129 if (hBitmap)
Alexandre Julliard491502b1997-11-01 19:08:16 +0000130 {
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000131 BITMAP bm;
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000132 GetObjectW(hBitmap, sizeof(bm), &bm);
Alexandre Julliardde424282001-08-10 22:51:42 +0000133 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000134 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
Alexandre Julliard491502b1997-11-01 19:08:16 +0000135 }
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000136 return hOldBitmap;
Alexandre Julliard491502b1997-11-01 19:08:16 +0000137}
138
Alexandre Julliardaca05781994-10-17 18:12:41 +0000139/***********************************************************************
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000140 * STATIC_LoadIconA
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000141 *
142 * Load the icon for an SS_ICON control.
143 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000144static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name )
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000145{
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000146 HINSTANCE hInstance = (HINSTANCE)GetWindowLongA( hwnd, GWL_HINSTANCE );
Alexandre Julliardde424282001-08-10 22:51:42 +0000147 HICON hicon = LoadIconA( hInstance, name );
Alexandre Julliard2682bc22000-11-27 22:03:23 +0000148 if (!hicon) hicon = LoadIconA( 0, name );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000149 return hicon;
150}
151
Alexandre Julliard491502b1997-11-01 19:08:16 +0000152/***********************************************************************
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000153 * STATIC_LoadIconW
154 *
155 * Load the icon for an SS_ICON control.
156 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000157static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name )
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000158{
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000159 HINSTANCE hInstance = (HINSTANCE)GetWindowLongA( hwnd, GWL_HINSTANCE );
Alexandre Julliardde424282001-08-10 22:51:42 +0000160 HICON hicon = LoadIconW( hInstance, name );
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000161 if (!hicon) hicon = LoadIconW( 0, name );
162 return hicon;
163}
164
165/***********************************************************************
166 * STATIC_LoadBitmapA
Alexandre Julliard491502b1997-11-01 19:08:16 +0000167 *
168 * Load the bitmap for an SS_BITMAP control.
169 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000170static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
Alexandre Julliard491502b1997-11-01 19:08:16 +0000171{
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000172 HINSTANCE hInstance = (HINSTANCE)GetWindowLongA( hwnd, GWL_HINSTANCE );
Alexandre Julliardde424282001-08-10 22:51:42 +0000173 HBITMAP hbitmap = LoadBitmapA( hInstance, name );
Alexandre Julliard2682bc22000-11-27 22:03:23 +0000174 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
175 hbitmap = LoadBitmapA( 0, name );
Alexandre Julliard491502b1997-11-01 19:08:16 +0000176 return hbitmap;
177}
178
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000179/***********************************************************************
180 * STATIC_LoadBitmapW
181 *
182 * Load the bitmap for an SS_BITMAP control.
183 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000184static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000185{
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000186 HINSTANCE hInstance = (HINSTANCE)GetWindowLongA( hwnd, GWL_HINSTANCE );
Alexandre Julliardde424282001-08-10 22:51:42 +0000187 HBITMAP hbitmap = LoadBitmapW( hInstance, name );
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000188 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
189 hbitmap = LoadBitmapW( 0, name );
190 return hbitmap;
191}
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000192
193/***********************************************************************
Guy Albertellibde5cf02002-01-31 21:02:17 +0000194 * STATIC_TryPaintFcn
195 *
196 * Try to immediately paint the control.
197 */
198static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
199{
200 LONG style = full_style & SS_TYPEMASK;
201 RECT rc;
202
203 GetClientRect( hwnd, &rc );
204 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
205 {
206 HDC hdc;
207 hdc = GetDC( hwnd );
208 (staticPaintFunc[style])( hwnd, hdc, full_style );
209 ReleaseDC( hwnd, hdc );
210 }
211}
212
213/***********************************************************************
Alexandre Julliardde424282001-08-10 22:51:42 +0000214 * StaticWndProc_common
Alexandre Julliardaca05781994-10-17 18:12:41 +0000215 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000216static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000217 LPARAM lParam, BOOL unicode )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000218{
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000219 LRESULT lResult = 0;
Alexandre Julliardde424282001-08-10 22:51:42 +0000220 LONG full_style = GetWindowLongA( hwnd, GWL_STYLE );
221 LONG style = full_style & SS_TYPEMASK;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000222
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000223 switch (uMsg)
224 {
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000225 case WM_CREATE:
Alexandre Julliard491502b1997-11-01 19:08:16 +0000226 if (style < 0L || style > SS_TYPEMASK)
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000227 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000228 ERR("Unknown style 0x%02lx\n", style );
Alexandre Julliardde424282001-08-10 22:51:42 +0000229 return -1;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000230 }
231 /* initialise colours */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000232 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
233 color_background = GetSysColor(COLOR_BACKGROUND);
234 color_window = GetSysColor(COLOR_WINDOW);
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000235 break;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000236
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000237 case WM_NCDESTROY:
Huw D M Davies1fea6b91998-12-07 12:50:14 +0000238 if (style == SS_ICON) {
239/*
240 * FIXME
241 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
Vincent Béron9a624912002-05-31 23:06:46 +0000242 *
Huw D M Davies1fea6b91998-12-07 12:50:14 +0000243 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
244 * had already been loaded by the application the last thing we want to do is
245 * GlobalFree16 the handle.
246 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000247 break;
248 }
249 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
250 DefWindowProcA(hwnd, uMsg, wParam, lParam);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000251
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000252 case WM_PAINT:
253 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000254 PAINTSTRUCT ps;
Alexandre Julliardde424282001-08-10 22:51:42 +0000255 BeginPaint(hwnd, &ps);
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000256 if (staticPaintFunc[style])
Alexandre Julliardde424282001-08-10 22:51:42 +0000257 (staticPaintFunc[style])( hwnd, ps.hdc, full_style );
258 EndPaint(hwnd, &ps);
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000259 }
260 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000261
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000262 case WM_ENABLE:
Dmitry Timoshkovaba60df2002-04-09 01:34:48 +0000263 InvalidateRect(hwnd, NULL, TRUE);
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000264 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000265
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000266 case WM_SYSCOLORCHANGE:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000267 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
268 color_background = GetSysColor(COLOR_BACKGROUND);
269 color_window = GetSysColor(COLOR_WINDOW);
Alexandre Julliardde424282001-08-10 22:51:42 +0000270 InvalidateRect(hwnd, NULL, TRUE);
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000271 break;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000272
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000273 case WM_NCCREATE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000274 if ((TWEAK_WineLook > WIN31_LOOK) && (full_style & SS_SUNKEN))
275 SetWindowLongA( hwnd, GWL_EXSTYLE,
276 GetWindowLongA( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000277
278 if(unicode)
279 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
280 else
281 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
282 /* fall through */
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000283 case WM_SETTEXT:
Guy Albertellibde5cf02002-01-31 21:02:17 +0000284 switch (style) {
285 case SS_ICON:
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000286 {
287 HICON hIcon;
288 if(unicode)
Alexandre Julliardde424282001-08-10 22:51:42 +0000289 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam);
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000290 else
Alexandre Julliardde424282001-08-10 22:51:42 +0000291 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000292 /* FIXME : should we also return the previous hIcon here ??? */
Alexandre Julliardde424282001-08-10 22:51:42 +0000293 STATIC_SetIcon(hwnd, hIcon, style);
Guy Albertellibde5cf02002-01-31 21:02:17 +0000294 break;
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000295 }
Vincent Béron9a624912002-05-31 23:06:46 +0000296 case SS_BITMAP:
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000297 {
298 HBITMAP hBitmap;
299 if(unicode)
Alexandre Julliardde424282001-08-10 22:51:42 +0000300 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000301 else
Alexandre Julliardde424282001-08-10 22:51:42 +0000302 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
303 STATIC_SetBitmap(hwnd, hBitmap, style);
Guy Albertellibde5cf02002-01-31 21:02:17 +0000304 break;
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000305 }
Guy Albertellibde5cf02002-01-31 21:02:17 +0000306 case SS_LEFT:
307 case SS_CENTER:
308 case SS_RIGHT:
309 case SS_SIMPLE:
310 case SS_LEFTNOWORDWRAP:
311 {
312 if (HIWORD(lParam))
313 {
314 if(unicode)
315 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
316 else
317 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
318 }
319 if (uMsg == WM_SETTEXT)
320 STATIC_TryPaintFcn( hwnd, full_style );
321 break;
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000322 }
Guy Albertellibde5cf02002-01-31 21:02:17 +0000323 default:
324 if (HIWORD(lParam))
325 {
326 if(unicode)
327 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
328 else
329 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
330 }
331 if(uMsg == WM_SETTEXT)
Dmitry Timoshkovaba60df2002-04-09 01:34:48 +0000332 InvalidateRect(hwnd, NULL, TRUE);
Guy Albertellibde5cf02002-01-31 21:02:17 +0000333 }
Alexandre Julliardde424282001-08-10 22:51:42 +0000334 return 1; /* success. FIXME: check text length */
Alexandre Julliardaca05781994-10-17 18:12:41 +0000335
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000336 case WM_SETFONT:
Alexandre Julliardde424282001-08-10 22:51:42 +0000337 if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
338 SetWindowLongA( hwnd, HFONT_GWL_OFFSET, wParam );
Dmitry Timoshkovaba60df2002-04-09 01:34:48 +0000339 if (LOWORD(lParam))
340 InvalidateRect( hwnd, NULL, TRUE );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000341 break;
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000342
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000343 case WM_GETFONT:
Alexandre Julliardde424282001-08-10 22:51:42 +0000344 return GetWindowLongA( hwnd, HFONT_GWL_OFFSET );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000345
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000346 case WM_NCHITTEST:
Alexandre Julliardde424282001-08-10 22:51:42 +0000347 if (full_style & SS_NOTIFY)
348 return HTCLIENT;
Serge Ivanovbfe15b12000-06-01 22:46:51 +0000349 else
Alexandre Julliardde424282001-08-10 22:51:42 +0000350 return HTTRANSPARENT;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000351
352 case WM_GETDLGCODE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000353 return DLGC_STATIC;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000354
Alexandre Julliard491502b1997-11-01 19:08:16 +0000355 case STM_GETIMAGE:
356 case STM_GETICON16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000357 case STM_GETICON:
Alexandre Julliardde424282001-08-10 22:51:42 +0000358 return GetWindowLongA( hwnd, HICON_GWL_OFFSET );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000359
Alexandre Julliard491502b1997-11-01 19:08:16 +0000360 case STM_SETIMAGE:
Huw D M Daviesd552d982000-06-11 20:00:33 +0000361 switch(wParam) {
362 case IMAGE_BITMAP:
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000363 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, style );
Huw D M Daviesd552d982000-06-11 20:00:33 +0000364 break;
365 case IMAGE_ICON:
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000366 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, style );
Huw D M Daviesd552d982000-06-11 20:00:33 +0000367 break;
368 default:
369 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
370 break;
371 }
Dmitry Timoshkovaba60df2002-04-09 01:34:48 +0000372 InvalidateRect( hwnd, NULL, TRUE );
Alexandre Julliard491502b1997-11-01 19:08:16 +0000373 break;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000374
Alexandre Julliard491502b1997-11-01 19:08:16 +0000375 case STM_SETICON16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000376 case STM_SETICON:
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000377 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, style );
Dmitry Timoshkovaba60df2002-04-09 01:34:48 +0000378 InvalidateRect( hwnd, NULL, TRUE );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000379 break;
380
381 default:
Alexandre Julliardde424282001-08-10 22:51:42 +0000382 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
383 DefWindowProcA(hwnd, uMsg, wParam, lParam);
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000384 }
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000385 return lResult;
386}
387
388/***********************************************************************
389 * StaticWndProcA
390 */
391static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
392{
Alexandre Julliardde424282001-08-10 22:51:42 +0000393 if (!IsWindow( hWnd )) return 0;
394 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
Dmitry Timoshkov009c1f82001-01-05 22:20:57 +0000395}
396
397/***********************************************************************
398 * StaticWndProcW
399 */
400static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
401{
Alexandre Julliardde424282001-08-10 22:51:42 +0000402 if (!IsWindow( hWnd )) return 0;
403 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000404}
405
Alexandre Julliardde424282001-08-10 22:51:42 +0000406static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
Luc Tourangeaue84b6782000-02-07 16:01:04 +0000407{
408 DRAWITEMSTRUCT dis;
Alexandre Julliardde424282001-08-10 22:51:42 +0000409 LONG id = GetWindowLongA( hwnd, GWL_ID );
Luc Tourangeaue84b6782000-02-07 16:01:04 +0000410
411 dis.CtlType = ODT_STATIC;
Alexandre Julliardde424282001-08-10 22:51:42 +0000412 dis.CtlID = id;
Luc Tourangeaue84b6782000-02-07 16:01:04 +0000413 dis.itemID = 0;
414 dis.itemAction = ODA_DRAWENTIRE;
415 dis.itemState = 0;
Alexandre Julliardde424282001-08-10 22:51:42 +0000416 dis.hwndItem = hwnd;
Luc Tourangeaue84b6782000-02-07 16:01:04 +0000417 dis.hDC = hdc;
418 dis.itemData = 0;
Alexandre Julliardde424282001-08-10 22:51:42 +0000419 GetClientRect( hwnd, &dis.rcItem );
Luc Tourangeaue84b6782000-02-07 16:01:04 +0000420
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000421 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
Alexandre Julliardde424282001-08-10 22:51:42 +0000422 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
Luc Tourangeaue84b6782000-02-07 16:01:04 +0000423}
Alexandre Julliard0e607781993-11-03 19:23:37 +0000424
Alexandre Julliardde424282001-08-10 22:51:42 +0000425static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000426{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000427 RECT rc;
428 HBRUSH hBrush;
Alexandre Julliardde424282001-08-10 22:51:42 +0000429 HFONT hFont;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000430 WORD wFormat;
Alexandre Julliardde424282001-08-10 22:51:42 +0000431 INT len;
432 WCHAR *text;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000433
Alexandre Julliardde424282001-08-10 22:51:42 +0000434 GetClientRect( hwnd, &rc);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000435
Alexandre Julliard491502b1997-11-01 19:08:16 +0000436 switch (style & SS_TYPEMASK)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000437 {
438 case SS_LEFT:
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000439 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000440 break;
441
442 case SS_CENTER:
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000443 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000444 break;
445
446 case SS_RIGHT:
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000447 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000448 break;
449
450 case SS_SIMPLE:
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000451 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000452 break;
453
454 case SS_LEFTNOWORDWRAP:
Niclas Karlssona0dc4e41999-01-23 12:22:20 +0000455 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000456 break;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000457
458 default:
459 return;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000460 }
461
462 if (style & SS_NOPREFIX)
463 wFormat |= DT_NOPREFIX;
464
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000465 if ((hFont = (HFONT)GetWindowLongA( hwnd, HFONT_GWL_OFFSET ))) SelectObject( hdc, hFont );
Francis Beaudet28623621999-09-20 18:28:08 +0000466
Gerard Patel0e805aa2000-07-16 14:39:21 +0000467 if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
468 {
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000469 hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
470 (WPARAM)hdc, (LPARAM)hwnd );
Gerard Pateld36a3ef2001-03-10 19:16:26 +0000471 if (!hBrush) /* did the app forget to call defwindowproc ? */
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000472 hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
473 (WPARAM)hdc, (LPARAM)hwnd);
Alexandre Julliardde424282001-08-10 22:51:42 +0000474 FillRect( hdc, &rc, hBrush );
Gerard Patel0e805aa2000-07-16 14:39:21 +0000475 }
Alexandre Julliardde424282001-08-10 22:51:42 +0000476 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
Francis Beaudet28623621999-09-20 18:28:08 +0000477
Alexandre Julliardde424282001-08-10 22:51:42 +0000478 if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
479 if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
480 SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
481 DrawTextW( hdc, text, -1, &rc, wFormat );
482 HeapFree( GetProcessHeap(), 0, text );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000483}
484
Alexandre Julliardde424282001-08-10 22:51:42 +0000485static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000486{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000487 RECT rc;
488 HBRUSH hBrush;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000489
Alexandre Julliardde424282001-08-10 22:51:42 +0000490 GetClientRect( hwnd, &rc);
Vincent Béron9a624912002-05-31 23:06:46 +0000491
Alexandre Julliardde424282001-08-10 22:51:42 +0000492 switch (style & SS_TYPEMASK)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000493 {
494 case SS_BLACKRECT:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000495 hBrush = CreateSolidBrush(color_windowframe);
496 FillRect( hdc, &rc, hBrush );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000497 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000498 case SS_GRAYRECT:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000499 hBrush = CreateSolidBrush(color_background);
500 FillRect( hdc, &rc, hBrush );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000501 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000502 case SS_WHITERECT:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000503 hBrush = CreateSolidBrush(color_window);
504 FillRect( hdc, &rc, hBrush );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000505 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000506 case SS_BLACKFRAME:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000507 hBrush = CreateSolidBrush(color_windowframe);
508 FrameRect( hdc, &rc, hBrush );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000509 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000510 case SS_GRAYFRAME:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000511 hBrush = CreateSolidBrush(color_background);
512 FrameRect( hdc, &rc, hBrush );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000513 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000514 case SS_WHITEFRAME:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000515 hBrush = CreateSolidBrush(color_window);
516 FrameRect( hdc, &rc, hBrush );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000517 break;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000518 default:
519 return;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000520 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000521 DeleteObject( hBrush );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000522}
523
524
Alexandre Julliardde424282001-08-10 22:51:42 +0000525static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000526{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000527 RECT rc;
528 HBRUSH hbrush;
Alexandre Julliardde424282001-08-10 22:51:42 +0000529 HICON hIcon;
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000530
Alexandre Julliardde424282001-08-10 22:51:42 +0000531 GetClientRect( hwnd, &rc );
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000532 hbrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
533 (WPARAM)hdc, (LPARAM)hwnd );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000534 FillRect( hdc, &rc, hbrush );
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000535 if ((hIcon = (HICON)GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
Alexandre Julliardde424282001-08-10 22:51:42 +0000536 DrawIcon( hdc, rc.left, rc.top, hIcon );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000537}
Alexandre Julliard491502b1997-11-01 19:08:16 +0000538
Alexandre Julliardde424282001-08-10 22:51:42 +0000539static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliard491502b1997-11-01 19:08:16 +0000540{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000541 RECT rc;
542 HBRUSH hbrush;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000543 HDC hMemDC;
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000544 HBITMAP hBitmap, oldbitmap;
Alexandre Julliard491502b1997-11-01 19:08:16 +0000545
Alexandre Julliardde424282001-08-10 22:51:42 +0000546 GetClientRect( hwnd, &rc );
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000547 hbrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
548 (WPARAM)hdc, (LPARAM)hwnd );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000549 FillRect( hdc, &rc, hbrush );
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000550
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000551 if ((hBitmap = (HBITMAP)GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
Alexandre Julliardde424282001-08-10 22:51:42 +0000552 {
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000553 BITMAP bm;
554 SIZE sz;
Alexandre Julliard491502b1997-11-01 19:08:16 +0000555
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000556 if(GetObjectType(hBitmap) != OBJ_BITMAP) return;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000557 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
Michael Stefaniucbc54d782002-10-10 21:22:09 +0000558 GetObjectW(hBitmap, sizeof(bm), &bm);
559 GetBitmapDimensionEx(hBitmap, &sz);
560 oldbitmap = SelectObject(hMemDC, hBitmap);
Huw D M Daviesdf78d681999-07-25 11:15:54 +0000561 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
562 SRCCOPY);
563 SelectObject(hMemDC, oldbitmap);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000564 DeleteDC(hMemDC);
Alexandre Julliard491502b1997-11-01 19:08:16 +0000565 }
566}
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000567
568
Alexandre Julliardde424282001-08-10 22:51:42 +0000569static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000570{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000571 RECT rc;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000572
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000573 if (TWEAK_WineLook == WIN31_LOOK)
574 return;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000575
Alexandre Julliardde424282001-08-10 22:51:42 +0000576 GetClientRect( hwnd, &rc );
577 switch (style & SS_TYPEMASK)
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000578 {
579 case SS_ETCHEDHORZ:
Marcus Meissner2e48a2c1999-10-31 17:36:26 +0000580 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000581 break;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000582 case SS_ETCHEDVERT:
Marcus Meissner2e48a2c1999-10-31 17:36:26 +0000583 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000584 break;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000585 case SS_ETCHEDFRAME:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000586 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000587 break;
588 }
589}