| 1 | /* $Id: static.cpp,v 1.5 1999-10-17 19:32:04 cbratschi Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Static control
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1999 Christoph Bratschi (ported from WINE)
|
|---|
| 6 | *
|
|---|
| 7 | * Copyright David W. Metcalfe, 1993
|
|---|
| 8 | *
|
|---|
| 9 | * WINE version: 990923
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #include <stdlib.h>
|
|---|
| 13 | #include "winuser.h"
|
|---|
| 14 | #include "winbase.h"
|
|---|
| 15 | #include "controls.h"
|
|---|
| 16 | #include "static.h"
|
|---|
| 17 |
|
|---|
| 18 | //Prototypes
|
|---|
| 19 |
|
|---|
| 20 | static void STATIC_PaintTextfn( HWND hwnd, HDC hdc );
|
|---|
| 21 | static void STATIC_PaintRectfn( HWND hwnd, HDC hdc );
|
|---|
| 22 | static void STATIC_PaintIconfn( HWND hwnd, HDC hdc );
|
|---|
| 23 | static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc );
|
|---|
| 24 | static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc );
|
|---|
| 25 |
|
|---|
| 26 | static COLORREF color_windowframe, color_background, color_window;
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | typedef void (*pfPaint)( HWND, HDC );
|
|---|
| 30 |
|
|---|
| 31 | static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
|
|---|
| 32 | {
|
|---|
| 33 | STATIC_PaintTextfn, /* SS_LEFT */
|
|---|
| 34 | STATIC_PaintTextfn, /* SS_CENTER */
|
|---|
| 35 | STATIC_PaintTextfn, /* SS_RIGHT */
|
|---|
| 36 | STATIC_PaintIconfn, /* SS_ICON */
|
|---|
| 37 | STATIC_PaintRectfn, /* SS_BLACKRECT */
|
|---|
| 38 | STATIC_PaintRectfn, /* SS_GRAYRECT */
|
|---|
| 39 | STATIC_PaintRectfn, /* SS_WHITERECT */
|
|---|
| 40 | STATIC_PaintRectfn, /* SS_BLACKFRAME */
|
|---|
| 41 | STATIC_PaintRectfn, /* SS_GRAYFRAME */
|
|---|
| 42 | STATIC_PaintRectfn, /* SS_WHITEFRAME */
|
|---|
| 43 | NULL, /* Not defined */
|
|---|
| 44 | STATIC_PaintTextfn, /* SS_SIMPLE */
|
|---|
| 45 | STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
|
|---|
| 46 | NULL, /* SS_OWNERDRAW */
|
|---|
| 47 | STATIC_PaintBitmapfn, /* SS_BITMAP */
|
|---|
| 48 | NULL, /* SS_ENHMETAFILE */
|
|---|
| 49 | STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
|
|---|
| 50 | STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
|
|---|
| 51 | STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | /***********************************************************************
|
|---|
| 56 | * STATIC_SetIcon
|
|---|
| 57 | *
|
|---|
| 58 | * Set the icon for an SS_ICON control.
|
|---|
| 59 | */
|
|---|
| 60 | static HICON STATIC_SetIcon( HWND hwnd, HICON hicon )
|
|---|
| 61 | {
|
|---|
| 62 | HICON prevIcon;
|
|---|
| 63 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
|---|
| 64 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 65 | ICONINFO ii;
|
|---|
| 66 | BITMAP bmp;
|
|---|
| 67 |
|
|---|
| 68 | if ((dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
|
|---|
| 69 |
|
|---|
| 70 | if (infoPtr->hIcon) DestroyIcon(infoPtr->hIcon);
|
|---|
| 71 | prevIcon = infoPtr->hIcon;
|
|---|
| 72 | infoPtr->hIcon = hicon;
|
|---|
| 73 |
|
|---|
| 74 | GetIconInfo(hicon,&ii);
|
|---|
| 75 | GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
|
|---|
| 76 |
|
|---|
| 77 | SetWindowPos(hwnd,0,0,0,bmp.bmWidth,bmp.bmHeight,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
|
|---|
| 78 |
|
|---|
| 79 | return prevIcon;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /***********************************************************************
|
|---|
| 83 | * STATIC_SetBitmap
|
|---|
| 84 | *
|
|---|
| 85 | * Set the bitmap for an SS_BITMAP control.
|
|---|
| 86 | */
|
|---|
| 87 | static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap )
|
|---|
| 88 | {
|
|---|
| 89 | HBITMAP hOldBitmap;
|
|---|
| 90 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
|---|
| 91 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 92 |
|
|---|
| 93 | if ((dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
|
|---|
| 94 |
|
|---|
| 95 | if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
|
|---|
| 96 | //ERR("huh? hBitmap!=0, but not bitmap\n");
|
|---|
| 97 | return 0;
|
|---|
| 98 | }
|
|---|
| 99 | hOldBitmap = infoPtr->hIcon;
|
|---|
| 100 | infoPtr->hIcon = hBitmap;
|
|---|
| 101 | if (hBitmap)
|
|---|
| 102 | {
|
|---|
| 103 | BITMAP bm;
|
|---|
| 104 | GetObjectA(hBitmap, sizeof(bm), &bm);
|
|---|
| 105 | SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
|
|---|
| 106 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
|
|---|
| 107 | }
|
|---|
| 108 | return hOldBitmap;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | /***********************************************************************
|
|---|
| 112 | * STATIC_LoadIcon
|
|---|
| 113 | *
|
|---|
| 114 | * Load the icon for an SS_ICON control.
|
|---|
| 115 | */
|
|---|
| 116 | static HICON STATIC_LoadIcon( HWND hwnd, LPCSTR name )
|
|---|
| 117 | {
|
|---|
| 118 | HICON hicon;
|
|---|
| 119 |
|
|---|
| 120 | hicon = LoadIconA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
|
|---|
| 121 |
|
|---|
| 122 | if (!hicon)
|
|---|
| 123 | hicon = LoadIconA(0, name);
|
|---|
| 124 |
|
|---|
| 125 | return hicon;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /***********************************************************************
|
|---|
| 129 | * STATIC_LoadBitmap
|
|---|
| 130 | *
|
|---|
| 131 | * Load the bitmap for an SS_BITMAP control.
|
|---|
| 132 | */
|
|---|
| 133 | static HBITMAP STATIC_LoadBitmap( HWND hwnd, LPCSTR name )
|
|---|
| 134 | {
|
|---|
| 135 | HBITMAP hbitmap;
|
|---|
| 136 |
|
|---|
| 137 | hbitmap = LoadBitmapA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
|
|---|
| 138 |
|
|---|
| 139 | if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
|
|---|
| 140 | hbitmap = LoadBitmapA(0,name);
|
|---|
| 141 |
|
|---|
| 142 | return hbitmap;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | /* message handler */
|
|---|
| 146 |
|
|---|
| 147 | LRESULT STATIC_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 148 | {
|
|---|
| 149 | CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
|
|---|
| 150 | STATICINFO* infoPtr;
|
|---|
| 151 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 152 | DWORD style = dwStyle & SS_TYPEMASK;
|
|---|
| 153 | DWORD dwExStyle = GetWindowLongA(hwnd,GWL_EXSTYLE);
|
|---|
| 154 |
|
|---|
| 155 | infoPtr = (STATICINFO*)malloc(sizeof(STATICINFO));
|
|---|
| 156 | infoPtr->hFont = 0;
|
|---|
| 157 | infoPtr->dummy = 0;
|
|---|
| 158 | infoPtr->hIcon = 0;
|
|---|
| 159 | SetInfoPtr(hwnd,(DWORD)infoPtr);
|
|---|
| 160 |
|
|---|
| 161 | if (dwStyle & SS_SUNKEN)
|
|---|
| 162 | {
|
|---|
| 163 | dwExStyle |= WS_EX_STATICEDGE;
|
|---|
| 164 | SetWindowLongA(hwnd,GWL_EXSTYLE,dwExStyle);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | if (style == SS_ICON)
|
|---|
| 168 | {
|
|---|
| 169 | if (cs->lpszName)
|
|---|
| 170 | {
|
|---|
| 171 | if (!HIWORD(cs->lpszName) || cs->lpszName[0])
|
|---|
| 172 | STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,cs->lpszName));
|
|---|
| 173 | }
|
|---|
| 174 | return TRUE;
|
|---|
| 175 | }
|
|---|
| 176 | if (style == SS_BITMAP)
|
|---|
| 177 | {
|
|---|
| 178 | if (cs->lpszName)
|
|---|
| 179 | STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,cs->lpszName));
|
|---|
| 180 | return TRUE;
|
|---|
| 181 | }
|
|---|
| 182 | if (!HIWORD(cs->lpszName) && (cs->lpszName)) return TRUE;
|
|---|
| 183 |
|
|---|
| 184 | return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | LRESULT STATIC_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 188 | {
|
|---|
| 189 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
|---|
| 190 |
|
|---|
| 191 | if (style < 0L || style > SS_TYPEMASK)
|
|---|
| 192 | {
|
|---|
| 193 | //Unknown style
|
|---|
| 194 | return (LRESULT)-1;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | /* initialise colours */
|
|---|
| 198 | color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
|---|
| 199 | color_background = GetSysColor(COLOR_BACKGROUND);
|
|---|
| 200 | color_window = GetSysColor(COLOR_WINDOW);
|
|---|
| 201 |
|
|---|
| 202 | return 0;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | LRESULT STATIC_NCDestroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 206 | {
|
|---|
| 207 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
|---|
| 208 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
|---|
| 209 |
|
|---|
| 210 | if (style == SS_ICON && infoPtr->hIcon)
|
|---|
| 211 | {
|
|---|
| 212 | DestroyIcon(infoPtr->hIcon);
|
|---|
| 213 | } else if (style == SS_BITMAP && infoPtr->hIcon)
|
|---|
| 214 | {
|
|---|
| 215 | DeleteObject(infoPtr->hIcon);
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | free(infoPtr);
|
|---|
| 219 |
|
|---|
| 220 | return DefWindowProcA(hwnd,WM_NCDESTROY,wParam,lParam);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | LRESULT STATIC_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 224 | {
|
|---|
| 225 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
|---|
| 226 | PAINTSTRUCT ps;
|
|---|
| 227 |
|
|---|
| 228 | BeginPaint(hwnd,&ps);
|
|---|
| 229 | if (staticPaintFunc[style]) (staticPaintFunc[style])(hwnd,ps.hdc);
|
|---|
| 230 | EndPaint(hwnd,&ps);
|
|---|
| 231 |
|
|---|
| 232 | return 0;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | LRESULT STATIC_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 236 | {
|
|---|
| 237 | InvalidateRect(hwnd,NULL,FALSE);
|
|---|
| 238 |
|
|---|
| 239 | return 0;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | LRESULT STATIC_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 243 | {
|
|---|
| 244 | color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
|---|
| 245 | color_background = GetSysColor(COLOR_BACKGROUND);
|
|---|
| 246 | color_window = GetSysColor(COLOR_WINDOW);
|
|---|
| 247 |
|
|---|
| 248 | InvalidateRect(hwnd,NULL,TRUE);
|
|---|
| 249 |
|
|---|
| 250 | return 0;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | LRESULT STATIC_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 254 | {
|
|---|
| 255 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
|---|
| 256 |
|
|---|
| 257 | if (style == SS_ICON)
|
|---|
| 258 | STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,(LPCSTR)lParam));
|
|---|
| 259 | else if (style == SS_BITMAP)
|
|---|
| 260 | STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,(LPCSTR)lParam));
|
|---|
| 261 | else
|
|---|
| 262 | DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
|
|---|
| 263 |
|
|---|
| 264 | InvalidateRect(hwnd,NULL,FALSE);
|
|---|
| 265 | UpdateWindow(hwnd);
|
|---|
| 266 |
|
|---|
| 267 | return 0;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | LRESULT STATIC_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 271 | {
|
|---|
| 272 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
|---|
| 273 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
|---|
| 274 |
|
|---|
| 275 | if (style == SS_ICON) return 0;
|
|---|
| 276 | if (style == SS_BITMAP) return 0;
|
|---|
| 277 |
|
|---|
| 278 | infoPtr->hFont = (HFONT)wParam;
|
|---|
| 279 |
|
|---|
| 280 | if (LOWORD(lParam))
|
|---|
| 281 | {
|
|---|
| 282 | InvalidateRect(hwnd,NULL,FALSE);
|
|---|
| 283 | UpdateWindow(hwnd);
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | return 0;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | LRESULT STATIC_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 290 | {
|
|---|
| 291 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
|---|
| 292 |
|
|---|
| 293 | return infoPtr->hFont;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | LRESULT STATIC_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 297 | {
|
|---|
| 298 | return HTTRANSPARENT;
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | LRESULT STATIC_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 302 | {
|
|---|
| 303 | return DLGC_STATIC;
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | LRESULT STATIC_GetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 307 | {
|
|---|
| 308 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
|---|
| 309 |
|
|---|
| 310 | return infoPtr->hIcon;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | LRESULT STATIC_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 314 | {
|
|---|
| 315 | LRESULT lResult;
|
|---|
| 316 |
|
|---|
| 317 | switch (wParam)
|
|---|
| 318 | {
|
|---|
| 319 | case IMAGE_CURSOR:
|
|---|
| 320 | case IMAGE_ICON:
|
|---|
| 321 | lResult = STATIC_SetIcon(hwnd,(HICON)lParam);
|
|---|
| 322 | break;
|
|---|
| 323 | case IMAGE_BITMAP:
|
|---|
| 324 | lResult = STATIC_SetBitmap(hwnd,(HBITMAP)lParam);
|
|---|
| 325 | case IMAGE_ENHMETAFILE:
|
|---|
| 326 | return 0; //CB: not supported!
|
|---|
| 327 | default:
|
|---|
| 328 | return 0;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | InvalidateRect(hwnd,NULL,FALSE);
|
|---|
| 332 | UpdateWindow(hwnd);
|
|---|
| 333 |
|
|---|
| 334 | return lResult;
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | LRESULT STATIC_SetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 338 | {
|
|---|
| 339 | LRESULT lResult;
|
|---|
| 340 |
|
|---|
| 341 | lResult = STATIC_SetIcon(hwnd,(HICON)wParam);
|
|---|
| 342 |
|
|---|
| 343 | InvalidateRect(hwnd,NULL,FALSE);
|
|---|
| 344 | UpdateWindow(hwnd);
|
|---|
| 345 |
|
|---|
| 346 | return lResult;
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | /***********************************************************************
|
|---|
| 350 | * StaticWndProc
|
|---|
| 351 | */
|
|---|
| 352 | LRESULT WINAPI StaticWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
|---|
| 353 | {
|
|---|
| 354 | switch (uMsg)
|
|---|
| 355 | {
|
|---|
| 356 | case WM_NCCREATE:
|
|---|
| 357 | return STATIC_NCCreate(hwnd,wParam,lParam);
|
|---|
| 358 |
|
|---|
| 359 | case WM_CREATE:
|
|---|
| 360 | return STATIC_Create(hwnd,wParam,lParam);
|
|---|
| 361 |
|
|---|
| 362 | case WM_NCDESTROY:
|
|---|
| 363 | return STATIC_NCDestroy(hwnd,wParam,lParam);
|
|---|
| 364 |
|
|---|
| 365 | case WM_PAINT:
|
|---|
| 366 | return STATIC_Paint(hwnd,wParam,lParam);
|
|---|
| 367 |
|
|---|
| 368 | case WM_ENABLE:
|
|---|
| 369 | return STATIC_Enable(hwnd,wParam,lParam);
|
|---|
| 370 |
|
|---|
| 371 | case WM_SYSCOLORCHANGE:
|
|---|
| 372 | return STATIC_SysColorChange(hwnd,wParam,lParam);
|
|---|
| 373 |
|
|---|
| 374 | case WM_SETTEXT:
|
|---|
| 375 | return STATIC_SetText(hwnd,wParam,lParam);
|
|---|
| 376 |
|
|---|
| 377 | case WM_SETFONT:
|
|---|
| 378 | return STATIC_SetFont(hwnd,wParam,lParam);
|
|---|
| 379 |
|
|---|
| 380 | case WM_GETFONT:
|
|---|
| 381 | return STATIC_GetFont(hwnd,wParam,lParam);
|
|---|
| 382 |
|
|---|
| 383 | case WM_NCHITTEST:
|
|---|
| 384 | return STATIC_NCHitTest(hwnd,wParam,lParam);
|
|---|
| 385 |
|
|---|
| 386 | case WM_GETDLGCODE:
|
|---|
| 387 | return STATIC_GetDlgCode(hwnd,wParam,lParam);
|
|---|
| 388 |
|
|---|
| 389 | case STM_GETIMAGE:
|
|---|
| 390 | case STM_GETICON:
|
|---|
| 391 | return STATIC_GetIcon(hwnd,wParam,lParam);
|
|---|
| 392 |
|
|---|
| 393 | case STM_SETIMAGE:
|
|---|
| 394 | return STATIC_SetImage(hwnd,wParam,lParam);
|
|---|
| 395 |
|
|---|
| 396 | case STM_SETICON:
|
|---|
| 397 | return STATIC_SetIcon(hwnd,wParam,lParam);
|
|---|
| 398 |
|
|---|
| 399 | default:
|
|---|
| 400 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
|---|
| 401 | break;
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
|---|
| 405 | }
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 | static void STATIC_PaintTextfn(HWND hwnd, HDC hdc )
|
|---|
| 409 | {
|
|---|
| 410 | RECT rc;
|
|---|
| 411 | HBRUSH hBrush;
|
|---|
| 412 | WORD wFormat;
|
|---|
| 413 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 414 | LONG style = dwStyle;
|
|---|
| 415 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
|---|
| 416 | INT textLen;
|
|---|
| 417 |
|
|---|
| 418 | GetClientRect(hwnd,&rc);
|
|---|
| 419 |
|
|---|
| 420 | switch (style & SS_TYPEMASK)
|
|---|
| 421 | {
|
|---|
| 422 | case SS_LEFT:
|
|---|
| 423 | wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
|---|
| 424 | break;
|
|---|
| 425 |
|
|---|
| 426 | case SS_CENTER:
|
|---|
| 427 | wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
|---|
| 428 | break;
|
|---|
| 429 |
|
|---|
| 430 | case SS_RIGHT:
|
|---|
| 431 | wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
|---|
| 432 | break;
|
|---|
| 433 |
|
|---|
| 434 | case SS_SIMPLE:
|
|---|
| 435 | wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
|
|---|
| 436 | break;
|
|---|
| 437 |
|
|---|
| 438 | case SS_LEFTNOWORDWRAP:
|
|---|
| 439 | wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
|
|---|
| 440 | break;
|
|---|
| 441 |
|
|---|
| 442 | default:
|
|---|
| 443 | return;
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | if (style & SS_NOPREFIX)
|
|---|
| 447 | wFormat |= DT_NOPREFIX;
|
|---|
| 448 |
|
|---|
| 449 | if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
|
|---|
| 450 | hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
|---|
| 451 | hdc, hwnd );
|
|---|
| 452 | if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
|
|---|
| 453 | FillRect( hdc, &rc, hBrush );
|
|---|
| 454 |
|
|---|
| 455 | if (!IsWindowEnabled(hwnd)) SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
|
|---|
| 456 |
|
|---|
| 457 | textLen = GetWindowTextLengthA(hwnd);
|
|---|
| 458 | if (textLen > 0)
|
|---|
| 459 | {
|
|---|
| 460 | char* text;
|
|---|
| 461 |
|
|---|
| 462 | textLen++;
|
|---|
| 463 | text = (char*)malloc(textLen);
|
|---|
| 464 | GetWindowTextA(hwnd,text,textLen);
|
|---|
| 465 | DrawTextA( hdc, text, -1, &rc, wFormat );
|
|---|
| 466 | free(text);
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | static void STATIC_PaintRectfn( HWND hwnd, HDC hdc )
|
|---|
| 471 | {
|
|---|
| 472 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 473 | RECT rc;
|
|---|
| 474 | HBRUSH hBrush;
|
|---|
| 475 |
|
|---|
| 476 | GetClientRect( hwnd, &rc);
|
|---|
| 477 |
|
|---|
| 478 | switch (dwStyle & SS_TYPEMASK)
|
|---|
| 479 | {
|
|---|
| 480 | case SS_BLACKRECT:
|
|---|
| 481 | hBrush = CreateSolidBrush(color_windowframe);
|
|---|
| 482 | FillRect( hdc, &rc, hBrush );
|
|---|
| 483 | break;
|
|---|
| 484 | case SS_GRAYRECT:
|
|---|
| 485 | hBrush = CreateSolidBrush(color_background);
|
|---|
| 486 | FillRect( hdc, &rc, hBrush );
|
|---|
| 487 | break;
|
|---|
| 488 | case SS_WHITERECT:
|
|---|
| 489 | hBrush = CreateSolidBrush(color_window);
|
|---|
| 490 | FillRect( hdc, &rc, hBrush );
|
|---|
| 491 | break;
|
|---|
| 492 | case SS_BLACKFRAME:
|
|---|
| 493 | hBrush = CreateSolidBrush(color_windowframe);
|
|---|
| 494 | FrameRect( hdc, &rc, hBrush );
|
|---|
| 495 | break;
|
|---|
| 496 | case SS_GRAYFRAME:
|
|---|
| 497 | hBrush = CreateSolidBrush(color_background);
|
|---|
| 498 | FrameRect( hdc, &rc, hBrush );
|
|---|
| 499 | break;
|
|---|
| 500 | case SS_WHITEFRAME:
|
|---|
| 501 | hBrush = CreateSolidBrush(color_window);
|
|---|
| 502 | FrameRect( hdc, &rc, hBrush );
|
|---|
| 503 | break;
|
|---|
| 504 | default:
|
|---|
| 505 | return;
|
|---|
| 506 | }
|
|---|
| 507 | DeleteObject( hBrush );
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 | static void STATIC_PaintIconfn( HWND hwnd, HDC hdc )
|
|---|
| 512 | {
|
|---|
| 513 | RECT rc;
|
|---|
| 514 | HBRUSH hbrush;
|
|---|
| 515 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
|---|
| 516 |
|
|---|
| 517 | GetClientRect( hwnd, &rc );
|
|---|
| 518 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
|---|
| 519 | hdc, hwnd );
|
|---|
| 520 | FillRect( hdc, &rc, hbrush );
|
|---|
| 521 | if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc )
|
|---|
| 525 | {
|
|---|
| 526 | RECT rc;
|
|---|
| 527 | HBRUSH hbrush;
|
|---|
| 528 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
|---|
| 529 | HDC hMemDC;
|
|---|
| 530 | HBITMAP oldbitmap;
|
|---|
| 531 |
|
|---|
| 532 | GetClientRect( hwnd, &rc );
|
|---|
| 533 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
|---|
| 534 | hdc, hwnd );
|
|---|
| 535 | FillRect( hdc, &rc, hbrush );
|
|---|
| 536 |
|
|---|
| 537 | if (infoPtr->hIcon) {
|
|---|
| 538 | BITMAP bm;
|
|---|
| 539 | SIZE sz;
|
|---|
| 540 |
|
|---|
| 541 | if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP)
|
|---|
| 542 | return;
|
|---|
| 543 | if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
|
|---|
| 544 | GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
|
|---|
| 545 | GetBitmapDimensionEx(infoPtr->hIcon, &sz);
|
|---|
| 546 | oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
|
|---|
| 547 | BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
|
|---|
| 548 | SRCCOPY);
|
|---|
| 549 | SelectObject(hMemDC, oldbitmap);
|
|---|
| 550 | DeleteDC(hMemDC);
|
|---|
| 551 | }
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 | static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc )
|
|---|
| 556 | {
|
|---|
| 557 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 558 | RECT rc;
|
|---|
| 559 | HBRUSH hbrush;
|
|---|
| 560 | HPEN hpen;
|
|---|
| 561 |
|
|---|
| 562 | GetClientRect( hwnd, &rc );
|
|---|
| 563 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
|---|
| 564 | hdc, hwnd );
|
|---|
| 565 | FillRect( hdc, &rc, hbrush );
|
|---|
| 566 |
|
|---|
| 567 | switch (dwStyle & SS_TYPEMASK)
|
|---|
| 568 | {
|
|---|
| 569 | case SS_ETCHEDHORZ:
|
|---|
| 570 | hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
|
|---|
| 571 | MoveToEx (hdc, rc.left, rc.bottom / 2 - 1, NULL);
|
|---|
| 572 | LineTo (hdc, rc.right - 1, rc.bottom / 2 - 1);
|
|---|
| 573 | SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
|
|---|
| 574 | MoveToEx (hdc, rc.left, rc.bottom / 2, NULL);
|
|---|
| 575 | LineTo (hdc, rc.right, rc.bottom / 2);
|
|---|
| 576 | LineTo (hdc, rc.right, rc.bottom / 2 - 1);
|
|---|
| 577 | SelectObject (hdc, hpen);
|
|---|
| 578 | break;
|
|---|
| 579 |
|
|---|
| 580 | case SS_ETCHEDVERT:
|
|---|
| 581 | hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
|
|---|
| 582 | MoveToEx (hdc, rc.right / 2 - 1, rc.top, NULL);
|
|---|
| 583 | LineTo (hdc, rc.right / 2 - 1, rc.bottom - 1);
|
|---|
| 584 | SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
|
|---|
| 585 | MoveToEx (hdc, rc.right / 2, rc.top, NULL);
|
|---|
| 586 | LineTo (hdc, rc.right / 2, rc.bottom);
|
|---|
| 587 | LineTo (hdc, rc.right / 2 -1 , rc.bottom);
|
|---|
| 588 | SelectObject (hdc, hpen);
|
|---|
| 589 | break;
|
|---|
| 590 |
|
|---|
| 591 | case SS_ETCHEDFRAME:
|
|---|
| 592 | DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
|
|---|
| 593 | break;
|
|---|
| 594 | }
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | BOOL STATIC_Register()
|
|---|
| 598 | {
|
|---|
| 599 | WNDCLASSA wndClass;
|
|---|
| 600 |
|
|---|
| 601 | if (GlobalFindAtomA(STATICCLASSNAME)) return FALSE;
|
|---|
| 602 |
|
|---|
| 603 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
|---|
| 604 | wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_PARENTDC;
|
|---|
| 605 | wndClass.lpfnWndProc = (WNDPROC)StaticWndProc;
|
|---|
| 606 | wndClass.cbClsExtra = 0;
|
|---|
| 607 | wndClass.cbWndExtra = sizeof(STATICINFO);
|
|---|
| 608 | wndClass.hCursor = LoadCursorA (0,IDC_ARROWA);
|
|---|
| 609 | wndClass.hbrBackground = (HBRUSH)0;
|
|---|
| 610 | wndClass.lpszClassName = STATICCLASSNAME;
|
|---|
| 611 |
|
|---|
| 612 | return RegisterClassA(&wndClass);
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 | BOOL STATIC_Unregister()
|
|---|
| 617 | {
|
|---|
| 618 | if (GlobalFindAtomA (STATICCLASSNAME))
|
|---|
| 619 | return UnregisterClassA(STATICCLASSNAME,(HINSTANCE)NULL);
|
|---|
| 620 | else return FALSE;
|
|---|
| 621 | }
|
|---|