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