Added configure check for str[n]casecmp.
[wine/multimedia.git] / controls / static.c
blobcbe89f7e6bb2b6063b2532bc9729329d7c22ebf8
1 /*
2 * Static control
4 * Copyright David W. Metcalfe, 1993
6 */
8 #include "wine/winuser16.h"
9 #include "win.h"
10 #include "cursoricon.h"
11 #include "static.h"
12 #include "heap.h"
13 #include "debugtools.h"
14 #include "tweak.h"
16 DEFAULT_DEBUG_CHANNEL(static)
18 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc );
19 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc );
20 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc );
21 static void STATIC_PaintBitmapfn( WND *wndPtr, HDC hdc );
22 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc );
24 static COLORREF color_windowframe, color_background, color_window;
27 typedef void (*pfPaint)( WND *, HDC );
29 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
31 STATIC_PaintTextfn, /* SS_LEFT */
32 STATIC_PaintTextfn, /* SS_CENTER */
33 STATIC_PaintTextfn, /* SS_RIGHT */
34 STATIC_PaintIconfn, /* SS_ICON */
35 STATIC_PaintRectfn, /* SS_BLACKRECT */
36 STATIC_PaintRectfn, /* SS_GRAYRECT */
37 STATIC_PaintRectfn, /* SS_WHITERECT */
38 STATIC_PaintRectfn, /* SS_BLACKFRAME */
39 STATIC_PaintRectfn, /* SS_GRAYFRAME */
40 STATIC_PaintRectfn, /* SS_WHITEFRAME */
41 NULL, /* Not defined */
42 STATIC_PaintTextfn, /* SS_SIMPLE */
43 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
44 NULL, /* SS_OWNERDRAW */
45 STATIC_PaintBitmapfn, /* SS_BITMAP */
46 NULL, /* SS_ENHMETAFILE */
47 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
48 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
49 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
53 /***********************************************************************
54 * STATIC_SetIcon
56 * Set the icon for an SS_ICON control.
58 static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
60 HICON16 prevIcon;
61 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
62 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
64 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
65 if (hicon && !info) {
66 ERR("huh? hicon!=0, but info=0???\n");
67 return 0;
69 prevIcon = infoPtr->hIcon;
70 infoPtr->hIcon = hicon;
71 if (hicon)
73 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
74 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
75 GlobalUnlock16( hicon );
77 return prevIcon;
80 /***********************************************************************
81 * STATIC_SetBitmap
83 * Set the bitmap for an SS_BITMAP control.
85 static HBITMAP16 STATIC_SetBitmap( WND *wndPtr, HBITMAP16 hBitmap )
87 HBITMAP16 hOldBitmap;
88 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
90 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
91 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
92 ERR("huh? hBitmap!=0, but not bitmap\n");
93 return 0;
95 hOldBitmap = infoPtr->hIcon;
96 infoPtr->hIcon = hBitmap;
97 if (hBitmap)
99 BITMAP bm;
100 GetObjectA(hBitmap, sizeof(bm), &bm);
101 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, bm.bmWidth, bm.bmHeight,
102 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
104 return hOldBitmap;
108 /***********************************************************************
109 * STATIC_LoadIcon
111 * Load the icon for an SS_ICON control.
113 static HICON16 STATIC_LoadIcon( WND *wndPtr, LPCSTR name )
115 HICON16 hicon;
117 if (wndPtr->flags & WIN_ISWIN32)
119 if (!HIWORD(wndPtr->hInstance)) {
120 LPSTR segname = SEGPTR_STRDUP(name);
121 hicon = LoadIcon16( wndPtr->hInstance, SEGPTR_GET(segname) );
122 SEGPTR_FREE(segname);
123 } else
124 hicon = LoadIconA( wndPtr->hInstance, name );
125 } else {
126 LPSTR segname = SEGPTR_STRDUP(name);
128 if (HIWORD(wndPtr->hInstance))
129 FIXME("win16 window class, but win32 hinstance??\n");
130 hicon = LoadIcon16( wndPtr->hInstance, SEGPTR_GET(segname) );
131 SEGPTR_FREE(segname);
133 if (!hicon)
134 hicon = LoadIconA( 0, name );
135 return hicon;
138 /***********************************************************************
139 * STATIC_LoadBitmap
141 * Load the bitmap for an SS_BITMAP control.
143 static HBITMAP16 STATIC_LoadBitmap( WND *wndPtr, LPCSTR name )
145 HBITMAP16 hbitmap;
147 if (wndPtr->flags & WIN_ISWIN32)
149 hbitmap = LoadBitmapA( wndPtr->hInstance, name );
150 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
151 hbitmap = LoadBitmapA( 0, name );
153 else
155 LPSTR segname = SEGPTR_STRDUP(name);
156 hbitmap = LoadBitmap16( wndPtr->hInstance, SEGPTR_GET(segname) );
157 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
158 hbitmap = LoadBitmapA( 0, segname );
159 SEGPTR_FREE(segname);
161 return hbitmap;
165 /***********************************************************************
166 * StaticWndProc
168 LRESULT WINAPI StaticWndProc( HWND hWnd, UINT uMsg, WPARAM wParam,
169 LPARAM lParam )
171 LRESULT lResult = 0;
172 WND *wndPtr = WIN_FindWndPtr(hWnd);
173 LONG style = wndPtr->dwStyle & SS_TYPEMASK;
174 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
176 switch (uMsg)
178 case WM_NCCREATE: {
179 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
181 if ((TWEAK_WineLook > WIN31_LOOK) && (wndPtr->dwStyle & SS_SUNKEN))
182 wndPtr->dwExStyle |= WS_EX_STATICEDGE;
184 if (style == SS_ICON)
186 if (cs->lpszName)
188 if (!HIWORD(cs->lpszName) || cs->lpszName[0])
189 STATIC_SetIcon( wndPtr,
190 STATIC_LoadIcon( wndPtr, cs->lpszName ));
192 lResult = 1;
193 goto END;
195 if (style == SS_BITMAP)
197 if (cs->lpszName)
198 STATIC_SetBitmap( wndPtr,
199 STATIC_LoadBitmap( wndPtr, cs->lpszName ));
200 WARN("style SS_BITMAP, dwStyle is 0x%08lx\n",
201 wndPtr->dwStyle);
202 lResult = 1;
203 goto END;
205 if (!HIWORD(cs->lpszName) && (cs->lpszName))
207 FIXME("windowName is 0x%04x, not doing DefWindowProc\n",
208 LOWORD(cs->lpszName));
209 lResult = 1;
210 goto END;
212 lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam );
213 goto END;
215 case WM_CREATE:
216 if (style < 0L || style > SS_TYPEMASK)
218 ERR("Unknown style 0x%02lx\n", style );
219 lResult = -1L;
220 break;
222 /* initialise colours */
223 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
224 color_background = GetSysColor(COLOR_BACKGROUND);
225 color_window = GetSysColor(COLOR_WINDOW);
226 break;
228 case WM_NCDESTROY:
229 if (style == SS_ICON) {
231 * FIXME
232 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
234 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
235 * had already been loaded by the application the last thing we want to do is
236 * GlobalFree16 the handle.
238 } else {
239 lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam );
241 break;
243 case WM_PAINT:
245 PAINTSTRUCT ps;
246 BeginPaint( hWnd, &ps );
247 if (staticPaintFunc[style])
248 (staticPaintFunc[style])( wndPtr, ps.hdc );
249 EndPaint( hWnd, &ps );
251 break;
253 case WM_ENABLE:
254 InvalidateRect( hWnd, NULL, FALSE );
255 break;
257 case WM_SYSCOLORCHANGE:
258 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
259 color_background = GetSysColor(COLOR_BACKGROUND);
260 color_window = GetSysColor(COLOR_WINDOW);
261 InvalidateRect( hWnd, NULL, TRUE );
262 break;
264 case WM_SETTEXT:
265 if (style == SS_ICON)
266 /* FIXME : should we also return the previous hIcon here ??? */
267 STATIC_SetIcon( wndPtr, STATIC_LoadIcon( wndPtr, (LPCSTR)lParam ));
268 else if (style == SS_BITMAP)
269 STATIC_SetBitmap(wndPtr,STATIC_LoadBitmap(wndPtr,(LPCSTR)lParam ));
270 else
271 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
272 InvalidateRect( hWnd, NULL, FALSE );
273 UpdateWindow( hWnd );
274 break;
276 case WM_SETFONT:
277 if (style == SS_ICON)
279 lResult = 0;
280 goto END;
282 if (style == SS_BITMAP)
284 lResult = 0;
285 goto END;
287 infoPtr->hFont = (HFONT16)wParam;
288 if (LOWORD(lParam))
290 InvalidateRect( hWnd, NULL, FALSE );
291 UpdateWindow( hWnd );
293 break;
295 case WM_GETFONT:
296 lResult = infoPtr->hFont;
297 goto END;
299 case WM_NCHITTEST:
300 lResult = HTTRANSPARENT;
301 goto END;
303 case WM_GETDLGCODE:
304 lResult = DLGC_STATIC;
305 goto END;
307 case STM_GETIMAGE:
308 case STM_GETICON16:
309 case STM_GETICON:
310 lResult = infoPtr->hIcon;
311 goto END;
313 case STM_SETIMAGE:
314 /* FIXME: handle wParam */
315 lResult = STATIC_SetBitmap( wndPtr, (HBITMAP)lParam );
316 InvalidateRect( hWnd, NULL, FALSE );
317 UpdateWindow( hWnd );
318 break;
320 case STM_SETICON16:
321 case STM_SETICON:
322 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
323 InvalidateRect( hWnd, NULL, FALSE );
324 UpdateWindow( hWnd );
325 break;
327 default:
328 lResult = DefWindowProcA(hWnd, uMsg, wParam, lParam);
329 break;
332 END:
333 WIN_ReleaseWndPtr(wndPtr);
334 return lResult;
338 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc )
340 RECT rc;
341 HBRUSH hBrush;
342 WORD wFormat;
344 LONG style = wndPtr->dwStyle;
345 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
347 GetClientRect( wndPtr->hwndSelf, &rc);
349 switch (style & SS_TYPEMASK)
351 case SS_LEFT:
352 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
353 break;
355 case SS_CENTER:
356 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
357 break;
359 case SS_RIGHT:
360 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
361 break;
363 case SS_SIMPLE:
364 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
365 break;
367 case SS_LEFTNOWORDWRAP:
368 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
369 break;
371 default:
372 return;
375 if (style & SS_NOPREFIX)
376 wFormat |= DT_NOPREFIX;
378 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
379 hBrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
380 hdc, wndPtr->hwndSelf );
381 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
382 FillRect( hdc, &rc, hBrush );
383 if (wndPtr->text) DrawTextA( hdc, wndPtr->text, -1, &rc, wFormat );
386 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc )
388 RECT rc;
389 HBRUSH hBrush;
391 GetClientRect( wndPtr->hwndSelf, &rc);
393 switch (wndPtr->dwStyle & SS_TYPEMASK)
395 case SS_BLACKRECT:
396 hBrush = CreateSolidBrush(color_windowframe);
397 FillRect( hdc, &rc, hBrush );
398 break;
399 case SS_GRAYRECT:
400 hBrush = CreateSolidBrush(color_background);
401 FillRect( hdc, &rc, hBrush );
402 break;
403 case SS_WHITERECT:
404 hBrush = CreateSolidBrush(color_window);
405 FillRect( hdc, &rc, hBrush );
406 break;
407 case SS_BLACKFRAME:
408 hBrush = CreateSolidBrush(color_windowframe);
409 FrameRect( hdc, &rc, hBrush );
410 break;
411 case SS_GRAYFRAME:
412 hBrush = CreateSolidBrush(color_background);
413 FrameRect( hdc, &rc, hBrush );
414 break;
415 case SS_WHITEFRAME:
416 hBrush = CreateSolidBrush(color_window);
417 FrameRect( hdc, &rc, hBrush );
418 break;
419 default:
420 return;
422 DeleteObject( hBrush );
426 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc )
428 RECT rc;
429 HBRUSH hbrush;
430 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
432 GetClientRect( wndPtr->hwndSelf, &rc );
433 hbrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
434 hdc, wndPtr->hwndSelf );
435 FillRect( hdc, &rc, hbrush );
436 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
439 static void STATIC_PaintBitmapfn(WND *wndPtr, HDC hdc )
441 RECT rc;
442 HBRUSH hbrush;
443 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
444 HDC hMemDC;
445 HBITMAP oldbitmap;
447 GetClientRect( wndPtr->hwndSelf, &rc );
448 hbrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
449 hdc, wndPtr->hwndSelf );
450 FillRect( hdc, &rc, hbrush );
452 if (infoPtr->hIcon) {
453 BITMAP bm;
454 SIZE sz;
456 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP)
457 return;
458 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
459 GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
460 GetBitmapDimensionEx(infoPtr->hIcon, &sz);
461 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
462 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
463 SRCCOPY);
464 SelectObject(hMemDC, oldbitmap);
465 DeleteDC(hMemDC);
470 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc )
472 RECT rc;
473 HBRUSH hbrush;
474 HPEN hpen;
476 if (TWEAK_WineLook == WIN31_LOOK)
477 return;
479 GetClientRect( wndPtr->hwndSelf, &rc );
480 hbrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
481 hdc, wndPtr->hwndSelf );
482 FillRect( hdc, &rc, hbrush );
484 switch (wndPtr->dwStyle & SS_TYPEMASK)
486 case SS_ETCHEDHORZ:
487 hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
488 MoveToEx (hdc, rc.left, rc.bottom / 2 - 1, NULL);
489 LineTo (hdc, rc.right - 1, rc.bottom / 2 - 1);
490 SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
491 MoveToEx (hdc, rc.left, rc.bottom / 2, NULL);
492 LineTo (hdc, rc.right, rc.bottom / 2);
493 LineTo (hdc, rc.right, rc.bottom / 2 - 1);
494 SelectObject (hdc, hpen);
495 break;
497 case SS_ETCHEDVERT:
498 hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
499 MoveToEx (hdc, rc.right / 2 - 1, rc.top, NULL);
500 LineTo (hdc, rc.right / 2 - 1, rc.bottom - 1);
501 SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
502 MoveToEx (hdc, rc.right / 2, rc.top, NULL);
503 LineTo (hdc, rc.right / 2, rc.bottom);
504 LineTo (hdc, rc.right / 2 -1 , rc.bottom);
505 SelectObject (hdc, hpen);
506 break;
508 case SS_ETCHEDFRAME:
509 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
510 break;