Changeset 1243 for trunk/src/user32/button.cpp
- Timestamp:
- Oct 10, 1999, 1:26:34 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/button.cpp
r1229 r1243 1 /* $Id: button.cpp,v 1. 7 1999-10-09 16:28:24 cbratschi Exp $ */1 /* $Id: button.cpp,v 1.8 1999-10-10 11:26:34 cbratschi Exp $ */ 2 2 /* File: button.cpp -- Button type widgets 3 3 * … … 10 10 */ 11 11 12 /* CB: todo13 - update checkboxes.bmp to Win9x style14 + color and transparent mask15 */16 17 12 #include <string.h> 18 13 #include <stdlib.h> … … 26 21 //Prototypes 27 22 28 static void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,UINT format);23 static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format); 29 24 30 25 static void PB_Paint(HWND hwnd,HDC hDC,WORD action); … … 693 688 if (textLen > 0 && (!(dwStyle & (BS_ICON|BS_BITMAP)))) 694 689 { 695 LOGBRUSH lb;696 697 690 textLen++; 698 691 text = (char*)malloc(textLen); 699 692 GetWindowTextA(hwnd,text,textLen); 700 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb ); 701 if (dwStyle & WS_DISABLED && GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)693 694 if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,DT_SINGLELINE | DT_CENTER | DT_VCENTER); else 702 695 { 703 dprintf(("Disable button")); 704 /* don't write gray text on gray background */ 705 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,text, 706 DT_CENTER | DT_VCENTER ); 707 } 708 else 709 { 710 dprintf(("Enable button")); 711 SetTextColor( hDC, (dwStyle & WS_DISABLED) ? 712 GetSysColor(COLOR_GRAYTEXT) : 713 GetSysColor(COLOR_BTNTEXT) ); 696 SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) ); 714 697 DrawTextA( hDC, text, -1, &rc, 715 698 DT_SINGLELINE | DT_CENTER | DT_VCENTER ); … … 802 785 } 803 786 787 SelectObject( hDC, hOldPen ); 788 SelectObject( hDC, hOldBrush ); 789 804 790 if (infoPtr->state & BUTTON_HASFOCUS) 805 791 { … … 807 793 DrawFocusRect( hDC, &focus_rect ); 808 794 } 809 810 811 SelectObject( hDC, hOldPen ); 812 SelectObject( hDC, hOldBrush ); 813 } 814 815 /********************************************************************** 816 * PB_Paint & CB_Paint sub function [internal] 817 * Paint text using a raster brush to avoid gray text on gray 818 * background. 'format' can be a combination of DT_CENTER and 819 * DT_VCENTER to use this function in both PB_PAINT and 820 * CB_PAINT. - Dirk Thierbach 821 * 822 * FIXME: This and TEXT_GrayString should be eventually combined, 823 * so calling one common function from PB_Paint, CB_Paint and 824 * TEXT_GrayString will be enough. Also note that this 825 * function ignores the CACHE_GetPattern funcs. 826 */ 827 828 static void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text, 829 UINT format) 830 { 831 /* This is the standard gray on gray pattern: 832 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55}; 833 */ 834 /* This pattern gives better readability with X Fonts. 835 FIXME: Maybe the user should be allowed to decide which he wants. */ 836 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF}; 837 838 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern ); 839 HDC hdcMem = CreateCompatibleDC(hDC); 840 HBITMAP hbmMem; 841 HBRUSH hBr; 842 RECT rect,rc2; 843 844 rect=*rc; 845 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT); 846 /* now text width and height are in rect.right and rect.bottom */ 847 rc2=rect; 848 rect.left = rect.top = 0; /* drawing pos in hdcMem */ 849 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2; 850 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2; 851 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom ); 852 SelectObject( hdcMem, hbmMem); 853 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS); 854 /* will be overwritten by DrawText, but just in case */ 855 if (hFont) SelectObject( hdcMem, hFont); 856 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE); 857 /* After draw: foreground = 0 bits, background = 1 bits */ 858 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) ); 859 DeleteObject( hbm ); 860 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229); 861 /* only keep the foreground bits where pattern is 1 */ 862 DeleteObject( SelectObject( hdcMem,hBr) ); 863 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND); 864 /* keep the background of the dest */ 865 DeleteDC( hdcMem); 866 DeleteObject( hbmMem ); 867 } 868 795 } 796 797 798 static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format) 799 { 800 COLORREF textColor = (GetSysColor(COLOR_GRAYTEXT) == GetBkColor(hdc)) ? COLOR_BTNTEXT:COLOR_GRAYTEXT; 801 RECT rect = *rtext; 802 COLORREF oldMode; 803 804 //CB: bug in Open32 DrawText: underscore is always black! -> two black lines! 805 SetTextColor(hdc,GetSysColor(COLOR_3DHILIGHT)); 806 DrawTextA(hdc,text,-1,&rect,format); 807 SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT)); 808 oldMode = SetBkMode(hdc,TRANSPARENT); 809 OffsetRect(&rect,-1,-1); 810 DrawTextA(hdc,text,-1,&rect,format); 811 SetBkMode(hdc,oldMode); 812 } 869 813 870 814 /********************************************************************** … … 955 899 if( text && action != ODA_SELECT ) 956 900 { 957 if (dwStyle & WS_DISABLED && 958 GetSysColor(COLOR_GRAYTEXT) == GetBkColor(hDC)) { 959 /* don't write gray text on gray background */ 960 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, text, 961 DT_VCENTER); 962 } else { 963 if (dwStyle & WS_DISABLED) 964 { 965 RECT rect = rtext; 966 COLORREF oldMode; 967 HPEN oldPen; 968 969 //CB: bug in Open32 DrawText: underscore is always black!, need workaround 970 // extract to PaintText(HDC hdc,char* text,RECT* rect); 971 SetTextColor(hDC,GetSysColor(COLOR_3DHILIGHT)); 972 oldPen = SelectObject(hDC,GetSysColorPen(COLOR_3DHIGHLIGHT)); 973 DrawTextA(hDC,text,-1,&rect,DT_SINGLELINE | DT_VCENTER); 974 SetTextColor(hDC,GetSysColor(COLOR_GRAYTEXT)); 975 SelectObject(hDC,GetSysColorPen(COLOR_GRAYTEXT)); 976 oldMode = SetBkMode(hDC,TRANSPARENT); 977 OffsetRect(&rect,-1,-1); 978 DrawTextA(hDC,text,-1,&rect,DT_SINGLELINE | DT_VCENTER); 979 SetBkMode(hDC,oldMode); 980 SelectObject(hDC,oldPen); 981 } else DrawTextA(hDC,text,-1,&rtext,DT_SINGLELINE | DT_VCENTER); 982 } 901 902 if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rtext,DT_SINGLELINE | DT_VCENTER); 903 else DrawTextA(hDC,text,-1,&rtext,DT_SINGLELINE | DT_VCENTER); 983 904 } 984 905 } … … 1065 986 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont ); 1066 987 rc.left += 10; 1067 if (dwStyle & WS_DISABLED && 1068 GetSysColor(COLOR_GRAYTEXT) == GetBkColor(hDC)) 1069 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,text,DT_SINGLELINE | DT_NOCLIP ); 1070 else 988 989 if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,DT_SINGLELINE | DT_NOCLIP); else 1071 990 { 1072 SetTextColor( hDC, (dwStyle & WS_DISABLED) ? 1073 GetSysColor(COLOR_GRAYTEXT) : 1074 GetSysColor(COLOR_BTNTEXT) ); 991 SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) ); 1075 992 DrawTextA( hDC, text, -1, &rc, 1076 993 DT_SINGLELINE | DT_NOCLIP );
Note:
See TracChangeset
for help on using the changeset viewer.