00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <os2win.h>
00028 #include "controls.h"
00029 #include "static.h"
00030
00031 #define DBG_LOCALLOG DBG_static
00032 #include "dbglocal.h"
00033
00034
00035
00036 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc );
00037 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc );
00038 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc );
00039 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc );
00040 static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc);
00041 static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc);
00042 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc );
00043
00044 static COLORREF color_windowframe, color_background, color_window;
00045
00046
00047 typedef void (*pfPaint)( HWND, HDC );
00048
00049 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
00050 {
00051 STATIC_PaintTextfn,
00052 STATIC_PaintTextfn,
00053 STATIC_PaintTextfn,
00054 STATIC_PaintIconfn,
00055 STATIC_PaintRectfn,
00056 STATIC_PaintRectfn,
00057 STATIC_PaintRectfn,
00058 STATIC_PaintRectfn,
00059 STATIC_PaintRectfn,
00060 STATIC_PaintRectfn,
00061 NULL,
00062 STATIC_PaintTextfn,
00063 STATIC_PaintTextfn,
00064 STATIC_PaintOwnerDrawfn,
00065 STATIC_PaintBitmapfn,
00066 STATIC_PaintMetafilefn,
00067 STATIC_PaintEtchedfn,
00068 STATIC_PaintEtchedfn,
00069 STATIC_PaintEtchedfn,
00070 };
00071
00072 static void STATIC_ResizeWindow(HWND hwnd,DWORD dwStyle,INT w,INT h)
00073 {
00074 if (dwStyle & SS_RIGHTJUST)
00075 {
00076 RECT rect;
00077
00078 GetWindowRect(hwnd,&rect);
00079 SetWindowPos(hwnd,0,rect.right-w,rect.bottom-h,w,h,SWP_NOACTIVATE | SWP_NOZORDER);
00080 } else SetWindowPos(hwnd,0,0,0,w,h,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
00081 }
00082
00083
00084
00085
00086
00087
00088 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon )
00089 {
00090 HICON prevIcon;
00091 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
00092 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00093 ICONINFO ii;
00094 BITMAP bmp;
00095
00096 if (infoPtr == NULL)
00097 return 0;
00098
00099 if ((dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
00100
00101 if (infoPtr->hIcon) DestroyIcon(infoPtr->hIcon);
00102 prevIcon = infoPtr->hIcon;
00103 infoPtr->hIcon = hicon;
00104
00105 if (!GetIconInfo(hicon,&ii)) return prevIcon;
00106 if (ii.hbmColor)
00107 GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
00108 else
00109 {
00110 GetObjectA(ii.hbmMask,sizeof(BITMAP),(LPVOID)&bmp);
00111 bmp.bmHeight /= 2;
00112 }
00113
00114 #if 1
00115
00116 if (!(dwStyle & (SS_CENTERIMAGE))) STATIC_ResizeWindow(hwnd,dwStyle,bmp.bmWidth,bmp.bmHeight);
00117 #else
00118 if (!(dwStyle & (SS_CENTERIMAGE | SS_REALSIZEIMAGE))) STATIC_ResizeWindow(hwnd,dwStyle,bmp.bmWidth,bmp.bmHeight);
00119 #endif
00120
00121 if (ii.hbmColor) DeleteObject(ii.hbmColor);
00122 if (ii.hbmMask) DeleteObject(ii.hbmMask);
00123
00124 return prevIcon;
00125 }
00126
00127
00128
00129
00130
00131
00132 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap )
00133 {
00134 HBITMAP hOldBitmap;
00135 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
00136 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00137
00138 if (infoPtr == NULL)
00139 return 0;
00140
00141 if ((dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
00142
00143 if (hBitmap && (GetObjectType(hBitmap) != OBJ_BITMAP)) {
00144
00145 return 0;
00146 }
00147 hOldBitmap = infoPtr->hIcon;
00148 infoPtr->hIcon = hBitmap;
00149 #if 1
00150
00151 if (hBitmap && !(dwStyle & (SS_CENTERIMAGE)))
00152 #else
00153 if (hBitmap && !(dwStyle & (SS_CENTERIMAGE | SS_REALSIZEIMAGE)))
00154 #endif
00155 {
00156 BITMAP bm;
00157
00158 GetObjectA(hBitmap,sizeof(bm),&bm);
00159 STATIC_ResizeWindow(hwnd,dwStyle,bm.bmWidth,bm.bmHeight);
00160 }
00161
00162 return hOldBitmap;
00163 }
00164
00165 static HENHMETAFILE STATIC_SetMetafile(HWND hwnd,HENHMETAFILE hMetafile)
00166 {
00167 HENHMETAFILE hOldMetafile;
00168
00169 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
00170 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00171
00172 if ((dwStyle & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
00173
00174 hOldMetafile = infoPtr->hIcon;
00175 infoPtr->hIcon = hMetafile;
00176
00177 return hOldMetafile;
00178 }
00179
00180
00181
00182
00183
00184
00185 static HICON STATIC_LoadIcon( HWND hwnd, LPCSTR name )
00186 {
00187 HICON hicon;
00188
00189 hicon = LoadIconA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
00190
00191 if (!hicon)
00192 hicon = LoadIconA(0, name);
00193
00194 return hicon;
00195 }
00196
00197
00198
00199
00200
00201
00202 static HBITMAP STATIC_LoadBitmap( HWND hwnd, LPCSTR name )
00203 {
00204 HBITMAP hbitmap;
00205
00206 hbitmap = LoadBitmapA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
00207
00208 if (!hbitmap)
00209 hbitmap = LoadBitmapA(0,name);
00210
00211 return hbitmap;
00212 }
00213
00214 static HBITMAP STATIC_LoadMetafile(HWND hwnd,LPCSTR name)
00215 {
00216 HENHMETAFILE hMetafile;
00217
00218 hMetafile = GetEnhMetaFileA(name);
00219
00220 return hMetafile;
00221 }
00222
00223
00224
00225 LRESULT STATIC_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
00226 {
00227 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
00228 STATICINFO* infoPtr;
00229 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00230 DWORD style = dwStyle & SS_TYPEMASK;
00231 DWORD dwExStyle = GetWindowLongA(hwnd,GWL_EXSTYLE);
00232
00233 infoPtr = (STATICINFO*)malloc(sizeof(STATICINFO));
00234 infoPtr->hFont = 0;
00235 infoPtr->dummy = 0;
00236 infoPtr->hIcon = 0;
00237 SetInfoPtr(hwnd,(DWORD)infoPtr);
00238
00239 if (dwStyle & SS_SUNKEN)
00240 {
00241 dwExStyle |= WS_EX_STATICEDGE;
00242 SetWindowLongA(hwnd,GWL_EXSTYLE,dwExStyle);
00243 }
00244
00245 if (style == SS_ICON)
00246 {
00247 if (cs->lpszName)
00248 {
00249 if (!HIWORD(cs->lpszName) || cs->lpszName[0])
00250 STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,cs->lpszName));
00251 }
00252 return TRUE;
00253 }
00254 if (style == SS_BITMAP)
00255 {
00256 if (cs->lpszName)
00257 STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,cs->lpszName));
00258 return TRUE;
00259 }
00260 if (style == SS_ENHMETAFILE)
00261 {
00262 if (cs->lpszName) STATIC_SetMetafile(hwnd,STATIC_LoadMetafile(hwnd,cs->lpszName));
00263 return TRUE;
00264 }
00265 if (!HIWORD(cs->lpszName) && (cs->lpszName)) return TRUE;
00266
00267 return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam);
00268 }
00269
00270 LRESULT STATIC_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
00271 {
00272 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00273
00274 if ((style < 0L) || (style > SS_TYPEMASK))
00275 {
00276
00277 return (LRESULT)-1;
00278 }
00279
00280
00281 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
00282 color_background = GetSysColor(COLOR_BACKGROUND);
00283 color_window = GetSysColor(COLOR_WINDOW);
00284
00285 return 0;
00286 }
00287
00288 LRESULT STATIC_NCDestroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
00289 {
00290 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
00291 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00292
00293 if ((style == SS_ICON) && infoPtr->hIcon)
00294 {
00295 DestroyIcon(infoPtr->hIcon);
00296 } else if ((style == SS_BITMAP) && infoPtr->hIcon)
00297 {
00298 DeleteObject(infoPtr->hIcon);
00299 } else if ((style == SS_ENHMETAFILE) && infoPtr->hIcon)
00300 {
00301 DeleteEnhMetaFile((HENHMETAFILE)infoPtr->hIcon);
00302 }
00303
00304 free(infoPtr);
00305
00306 return DefWindowProcA(hwnd,WM_NCDESTROY,wParam,lParam);
00307 }
00308
00309 LRESULT STATIC_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
00310 {
00311 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00312 PAINTSTRUCT ps;
00313
00314 BeginPaint(hwnd,&ps);
00315 if (staticPaintFunc[style]) (staticPaintFunc[style])(hwnd,ps.hdc);
00316 EndPaint(hwnd,&ps);
00317
00318 return 0;
00319 }
00320
00321 LRESULT STATIC_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
00322 {
00323 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00324
00325 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),wParam ? STN_ENABLE:STN_DISABLE),hwnd);
00326
00327 InvalidateRect(hwnd,NULL,FALSE);
00328
00329 return 0;
00330 }
00331
00332 LRESULT STATIC_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
00333 {
00334 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
00335 color_background = GetSysColor(COLOR_BACKGROUND);
00336 color_window = GetSysColor(COLOR_WINDOW);
00337
00338 InvalidateRect(hwnd,NULL,TRUE);
00339
00340 return 0;
00341 }
00342
00343 LRESULT STATIC_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
00344 {
00345 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00346
00347 if (style == SS_ICON)
00348 STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,(LPCSTR)lParam));
00349 else if (style == SS_BITMAP)
00350 STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,(LPCSTR)lParam));
00351 else if (style == SS_ENHMETAFILE)
00352 STATIC_SetMetafile(hwnd,STATIC_LoadMetafile(hwnd,(LPCSTR)lParam));
00353 else
00354 DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
00355
00356 InvalidateRect(hwnd,NULL,FALSE);
00357
00358 return TRUE;
00359 }
00360
00361 LRESULT STATIC_GetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
00362 {
00363 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00364
00365 if (style == SS_ICON)
00366 {
00367 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
00368
00369 if ((wParam < 4) || !lParam) return 0;
00370 memcpy((VOID*)lParam,&infoPtr->hIcon,4);
00371
00372 return 4;
00373 } else return DefWindowProcA(hwnd,WM_GETTEXT,wParam,lParam);
00374 }
00375
00376 LRESULT STATIC_GetTextLength(HWND hwnd,WPARAM wParam,LPARAM lParam)
00377 {
00378 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00379
00380 if (style == SS_ICON) return 4;
00381 else return DefWindowProcA(hwnd,WM_GETTEXTLENGTH,wParam,lParam);
00382 }
00383
00384 LRESULT STATIC_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
00385 {
00386 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
00387 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00388
00389 if (style == SS_ICON) return 0;
00390 if (style == SS_BITMAP) return 0;
00391 if (style == SS_ENHMETAFILE) return 0;
00392
00393 infoPtr->hFont = (HFONT)wParam;
00394
00395 if (LOWORD(lParam))
00396 {
00397 InvalidateRect(hwnd,NULL,FALSE);
00398 UpdateWindow(hwnd);
00399 }
00400
00401 return 0;
00402 }
00403
00404 LRESULT STATIC_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
00405 {
00406 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
00407
00408 return infoPtr->hFont;
00409 }
00410
00411 LRESULT STATIC_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
00412 {
00413 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00414 LRESULT lResult;
00415
00416 if (dwStyle & SS_NOTIFY)
00417 lResult = HTCLIENT;
00418 else lResult = HTTRANSPARENT;
00419
00420 return lResult;
00421 }
00422
00423 LRESULT STATIC_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
00424 {
00425 return DLGC_STATIC;
00426 }
00427
00428 LRESULT STATIC_GetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
00429 {
00430 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
00431
00432 return infoPtr->hIcon;
00433 }
00434
00435 LRESULT STATIC_GetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
00436 {
00437 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
00438 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
00439
00440 switch (wParam)
00441 {
00442 case IMAGE_BITMAP:
00443 if (style & SS_BITMAP) return infoPtr->hIcon;
00444 break;
00445
00446 case IMAGE_CURSOR:
00447 case IMAGE_ICON:
00448 if (style & SS_ICON) return infoPtr->hIcon;
00449 break;
00450
00451 case IMAGE_ENHMETAFILE:
00452 if (style & SS_ENHMETAFILE) return infoPtr->hIcon;
00453 break;
00454
00455 default:
00456 break;
00457 }
00458
00459 return 0;
00460 }
00461
00462 LRESULT STATIC_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
00463 {
00464 LRESULT lResult = 0;
00465
00466 switch (wParam)
00467 {
00468 case IMAGE_CURSOR:
00469 case IMAGE_ICON:
00470 lResult = STATIC_SetIcon(hwnd,(HICON)lParam);
00471 break;
00472
00473 case IMAGE_BITMAP:
00474 lResult = STATIC_SetBitmap(hwnd,(HBITMAP)lParam);
00475 break;
00476
00477 case IMAGE_ENHMETAFILE:
00478 lResult = STATIC_SetMetafile(hwnd,(HENHMETAFILE)lParam);
00479 break;
00480
00481 default:
00482 return 0;
00483 }
00484
00485 if (lResult) InvalidateRect(hwnd,NULL,FALSE);
00486
00487 return lResult;
00488 }
00489
00490 LRESULT STATIC_SetIconMsg(HWND hwnd,WPARAM wParam,LPARAM lParam)
00491 {
00492 LRESULT lResult;
00493
00494 lResult = STATIC_SetIcon(hwnd,(HICON)wParam);
00495
00496 InvalidateRect(hwnd,NULL,FALSE);
00497
00498 return lResult;
00499 }
00500
00501 LRESULT STATIC_Click(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
00502 {
00503 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00504
00505 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_CLICKED),hwnd);
00506
00507 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
00508 }
00509
00510 LRESULT STATIC_DoubleClick(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
00511 {
00512 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00513
00514 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_DBLCLK),hwnd);
00515
00516 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
00517 }
00518
00519
00520
00521
00522 LRESULT WINAPI StaticWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
00523 {
00524 switch (uMsg)
00525 {
00526 case WM_NCCREATE:
00527 return STATIC_NCCreate(hwnd,wParam,lParam);
00528
00529 case WM_CREATE:
00530 return STATIC_Create(hwnd,wParam,lParam);
00531
00532 case WM_NCDESTROY:
00533 return STATIC_NCDestroy(hwnd,wParam,lParam);
00534
00535 case WM_PAINT:
00536 return STATIC_Paint(hwnd,wParam,lParam);
00537
00538 case WM_ENABLE:
00539 return STATIC_Enable(hwnd,wParam,lParam);
00540
00541 case WM_SYSCOLORCHANGE:
00542 return STATIC_SysColorChange(hwnd,wParam,lParam);
00543
00544 case WM_SETTEXT:
00545 return STATIC_SetText(hwnd,wParam,lParam);
00546
00547 case WM_GETTEXT:
00548 return STATIC_GetText(hwnd,wParam,lParam);
00549
00550 case WM_GETTEXTLENGTH:
00551 return STATIC_GetTextLength(hwnd,wParam,lParam);
00552
00553 case WM_SETFONT:
00554 return STATIC_SetFont(hwnd,wParam,lParam);
00555
00556 case WM_GETFONT:
00557 return STATIC_GetFont(hwnd,wParam,lParam);
00558
00559 case WM_NCHITTEST:
00560 return STATIC_NCHitTest(hwnd,wParam,lParam);
00561
00562 case WM_GETDLGCODE:
00563 return STATIC_GetDlgCode(hwnd,wParam,lParam);
00564
00565 case WM_LBUTTONDOWN:
00566 case WM_NCLBUTTONDOWN:
00567 return STATIC_Click(hwnd,uMsg,wParam,lParam);
00568
00569 case WM_LBUTTONDBLCLK:
00570 case WM_NCLBUTTONDBLCLK:
00571 return STATIC_DoubleClick(hwnd,uMsg,wParam,lParam);
00572
00573 case STM_GETIMAGE:
00574 return STATIC_GetImage(hwnd,wParam,lParam);
00575
00576 case STM_GETICON:
00577 return STATIC_GetIcon(hwnd,wParam,lParam);
00578
00579 case STM_SETIMAGE:
00580 return STATIC_SetImage(hwnd,wParam,lParam);
00581
00582 case STM_SETICON:
00583 return STATIC_SetIconMsg(hwnd,wParam,lParam);
00584
00585 case STM_MSGMAX:
00586 return 0;
00587
00588 default:
00589 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
00590 break;
00591 }
00592
00593 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
00594 }
00595
00596
00597 static void STATIC_PaintTextfn(HWND hwnd, HDC hdc )
00598 {
00599 RECT rc;
00600 HBRUSH hBrush;
00601 WORD wFormat;
00602 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00603 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
00604 INT textLen;
00605
00606 GetClientRect(hwnd,&rc);
00607
00608 switch (dwStyle & SS_TYPEMASK)
00609 {
00610 case SS_LEFT:
00611 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
00612 break;
00613
00614 case SS_CENTER:
00615 case SS_CENTERIMAGE:
00616 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
00617 break;
00618
00619 case SS_RIGHT:
00620 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
00621 break;
00622
00623 case SS_SIMPLE:
00624 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
00625 break;
00626
00627 case SS_LEFTNOWORDWRAP:
00628 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
00629 break;
00630
00631 default:
00632 return;
00633 }
00634
00635 if (dwStyle & SS_NOPREFIX) wFormat |= DT_NOPREFIX;
00636 if (dwStyle & SS_ENDELLIPSIS) wFormat |= DT_END_ELLIPSIS;
00637 if (dwStyle & SS_PATHELLIPSIS) wFormat |= DT_PATH_ELLIPSIS;
00638 if (dwStyle & SS_WORDELLIPSIS) wFormat |= DT_WORD_ELLIPSIS;
00639
00640 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
00641
00642 #if 1
00643 if ((dwStyle & SS_NOPREFIX) || ((dwStyle & SS_TYPEMASK) != SS_SIMPLE))
00644 {
00645 hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
00646 hdc, hwnd );
00647 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
00648 FillRect( hdc, &rc, hBrush );
00649 }
00650 #else
00651 hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
00652 hdc, hwnd );
00653 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
00654 FillRect( hdc, &rc, hBrush );
00655 #endif
00656
00657 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
00658
00659 textLen = GetWindowTextLengthA(hwnd);
00660 if (textLen > 0)
00661 {
00662 char* text;
00663
00664 textLen++;
00665 text = (char*)malloc(textLen);
00666 GetWindowTextA(hwnd,text,textLen);
00667 DrawTextExA(hdc,text,-1,&rc,wFormat,NULL);
00668 free(text);
00669 }
00670 }
00671
00672 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc )
00673 {
00674 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00675 RECT rc;
00676 HBRUSH hBrush;
00677
00678 GetClientRect( hwnd, &rc);
00679
00680 switch (dwStyle & SS_TYPEMASK)
00681 {
00682 case SS_BLACKRECT:
00683 hBrush = CreateSolidBrush(color_windowframe);
00684 FillRect( hdc, &rc, hBrush );
00685 break;
00686 case SS_GRAYRECT:
00687 hBrush = CreateSolidBrush(color_background);
00688 FillRect( hdc, &rc, hBrush );
00689 break;
00690 case SS_WHITERECT:
00691 hBrush = CreateSolidBrush(color_window);
00692 FillRect( hdc, &rc, hBrush );
00693 break;
00694 case SS_BLACKFRAME:
00695 hBrush = CreateSolidBrush(color_windowframe);
00696 FrameRect( hdc, &rc, hBrush );
00697 break;
00698 case SS_GRAYFRAME:
00699 hBrush = CreateSolidBrush(color_background);
00700 FrameRect( hdc, &rc, hBrush );
00701 break;
00702 case SS_WHITEFRAME:
00703 hBrush = CreateSolidBrush(color_window);
00704 FrameRect( hdc, &rc, hBrush );
00705 break;
00706 default:
00707 return;
00708 }
00709 DeleteObject( hBrush );
00710 }
00711
00712
00713 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc )
00714 {
00715 RECT rc;
00716 HBRUSH hbrush;
00717 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
00718 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00719
00720 GetClientRect( hwnd, &rc );
00721 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
00722 hdc, hwnd );
00723 FillRect( hdc, &rc, hbrush );
00724
00725 if (dwStyle & SS_CENTERIMAGE)
00726 {
00727 ICONINFO ii;
00728 BITMAP bmp;
00729
00730 #if 0
00731
00732 COLORREF color;
00733
00734 color = GetPixel(hMemDC, 0, 0);
00735 hbrush = CreateSolidBrush(color);
00736 FillRect( hdc, &rc, hbrush );
00737 DeleteObject(hbrush);
00738 #endif
00739
00740 if (!GetIconInfo(infoPtr->hIcon,&ii)) return;
00741 if (ii.hbmColor)
00742 GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
00743 else
00744 {
00745 GetObjectA(ii.hbmMask,sizeof(BITMAP),(LPVOID)&bmp);
00746 bmp.bmHeight /= 2;
00747 }
00748 DrawIcon(hdc,(rc.right-bmp.bmWidth)/2,(rc.bottom-bmp.bmHeight)/2,infoPtr->hIcon);
00749 if (ii.hbmColor) DeleteObject(ii.hbmColor);
00750 if (ii.hbmMask) DeleteObject(ii.hbmMask);
00751 }
00752 else
00753 if (infoPtr->hIcon) {
00754 DrawIcon(hdc,rc.left,rc.top,infoPtr->hIcon);
00755 }
00756 }
00757
00758 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc )
00759 {
00760 RECT rc;
00761 HBRUSH hbrush;
00762 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
00763 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00764 HDC hMemDC;
00765 HBITMAP oldbitmap;
00766
00767 GetClientRect( hwnd, &rc );
00768 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
00769 hdc, hwnd );
00770
00771 if (infoPtr->hIcon)
00772 {
00773 BITMAP bm;
00774
00775 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP) return;
00776 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
00777
00778 GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
00779 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
00780
00781
00782 if(dwStyle & SS_CENTERIMAGE)
00783 {
00784 SIZE szbm;
00785 SIZE szdc;
00786 COLORREF color;
00787
00788
00789 color = GetPixel(hMemDC, 0, 0);
00790 hbrush = CreateSolidBrush(color);
00791 FillRect( hdc, &rc, hbrush );
00792 DeleteObject(hbrush);
00793
00794 if(bm.bmWidth > rc.right - rc.left)
00795 {
00796 szdc.cx = 0;
00797 szbm.cx = (bm.bmWidth - (rc.right - rc.left)) / 2;
00798 bm.bmWidth = rc.right - rc.left;
00799 }
00800 else
00801 {
00802 szbm.cx = 0;
00803 szdc.cx = ((rc.right - rc.left) - bm.bmWidth) / 2;
00804 }
00805 if(bm.bmHeight > rc.bottom - rc.top)
00806 {
00807 szdc.cy = 0;
00808 szbm.cy = (bm.bmHeight - (rc.bottom - rc.top)) / 2;
00809 bm.bmWidth = rc.bottom - rc.top;
00810 }
00811 else
00812 {
00813 szbm.cy = 0;
00814 szdc.cy = ((rc.bottom - rc.top) - bm.bmHeight) / 2;
00815 }
00816 BitBlt(hdc, szdc.cx, szdc.cy, bm.bmWidth, bm.bmHeight, hMemDC,
00817 szbm.cx, szbm.cy, SRCCOPY);
00818 }
00819 else
00820 {
00821 FillRect( hdc, &rc, hbrush );
00822 BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
00823 }
00824
00825 SelectObject(hMemDC, oldbitmap);
00826 DeleteDC(hMemDC);
00827 }
00828 }
00829
00830 static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc)
00831 {
00832 RECT rect;
00833 HBRUSH hbrush;
00834 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
00835
00836 GetClientRect(hwnd,&rect);
00837 hbrush = SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
00838 FillRect(hdc,&rect,hbrush);
00839
00840 if (infoPtr->hIcon) PlayEnhMetaFile(hdc,(HENHMETAFILE)infoPtr->hIcon,&rect);
00841 }
00842
00843 static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc)
00844 {
00845 DRAWITEMSTRUCT di;
00846
00847 di.CtlType = ODT_STATIC;
00848 di.CtlID = GetWindowLongA(hwnd,GWL_ID);
00849 di.itemID = 0;
00850 di.itemAction = ODA_DRAWENTIRE;
00851 di.itemState = ODS_DEFAULT;
00852 di.hwndItem = hwnd;
00853 di.hDC = hdc;
00854 GetClientRect(hwnd,&di.rcItem);
00855 di.itemData = 0;
00856
00857 SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
00858 SendMessageA(GetParent(hwnd),WM_DRAWITEM,di.CtlID,(LPARAM)&di);
00859 }
00860
00861 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc )
00862 {
00863 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
00864 RECT rc;
00865
00866 GetClientRect( hwnd, &rc );
00867 switch (dwStyle & SS_TYPEMASK)
00868 {
00869 case SS_ETCHEDHORZ:
00870 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
00871 break;
00872 case SS_ETCHEDVERT:
00873 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
00874 break;
00875 case SS_ETCHEDFRAME:
00876 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
00877 break;
00878 }
00879 }
00880
00881 BOOL STATIC_Register()
00882 {
00883 WNDCLASSA wndClass;
00884
00885
00886
00887
00888 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
00889 wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_PARENTDC;
00890 wndClass.lpfnWndProc = (WNDPROC)StaticWndProc;
00891 wndClass.cbClsExtra = 0;
00892 wndClass.cbWndExtra = sizeof(STATICINFO);
00893 wndClass.hCursor = LoadCursorA (0,IDC_ARROWA);
00894 wndClass.hbrBackground = (HBRUSH)0;
00895 wndClass.lpszClassName = STATICCLASSNAME;
00896
00897 return RegisterClassA(&wndClass);
00898 }
00899
00900
00901 BOOL STATIC_Unregister()
00902 {
00903 if (GlobalFindAtomA (STATICCLASSNAME))
00904 return UnregisterClassA(STATICCLASSNAME,(HINSTANCE)NULL);
00905 else return FALSE;
00906 }