Changeset 1243 for trunk/src


Ignore:
Timestamp:
Oct 10, 1999, 1:26:34 PM (26 years ago)
Author:
cbratschi
Message:

radio buttons fixed, disabled text output

Location:
trunk/src/user32
Files:
2 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 $ */
    22/* File: button.cpp -- Button type widgets
    33 *
     
    1010 */
    1111
    12 /* CB: todo
    13    - update checkboxes.bmp to Win9x style
    14      + color and transparent mask
    15 */
    16 
    1712#include <string.h>
    1813#include <stdlib.h>
     
    2621//Prototypes
    2722
    28 static void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,UINT format);
     23static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format);
    2924
    3025static void PB_Paint(HWND hwnd,HDC hDC,WORD action);
     
    693688    if (textLen > 0 && (!(dwStyle & (BS_ICON|BS_BITMAP))))
    694689    {
    695         LOGBRUSH lb;
    696 
    697690        textLen++;
    698691        text = (char*)malloc(textLen);
    699692        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
    702695        {
    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) );
    714697            DrawTextA( hDC, text, -1, &rc,
    715698                         DT_SINGLELINE | DT_CENTER | DT_VCENTER );
     
    802785    }
    803786
     787    SelectObject( hDC, hOldPen );
     788    SelectObject( hDC, hOldBrush );
     789
    804790    if (infoPtr->state & BUTTON_HASFOCUS)
    805791    {
     
    807793        DrawFocusRect( hDC, &focus_rect );
    808794    }
    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
     798static 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}
    869813
    870814/**********************************************************************
     
    955899        if( text && action != ODA_SELECT )
    956900        {
    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);
    983904        }
    984905    }
     
    1065986        if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
    1066987        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
    1071990        {
    1072             SetTextColor( hDC, (dwStyle & WS_DISABLED) ?
    1073                                  GetSysColor(COLOR_GRAYTEXT) :
    1074                                  GetSysColor(COLOR_BTNTEXT) );
     991            SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
    1075992            DrawTextA( hDC, text, -1, &rc,
    1076993                         DT_SINGLELINE | DT_NOCLIP );
  • trunk/src/user32/uitools.cpp

    r1229 r1243  
    1 /* $Id: uitools.cpp,v 1.11 1999-10-09 16:28:25 cbratschi Exp $ */
     1/* $Id: uitools.cpp,v 1.12 1999-10-10 11:26:34 cbratschi Exp $ */
    22/*
    33 * User Interface Functions
     
    797797
    798798    /* Define bounding box */
    799     i = 14*SmallDiam/16;
     799    i = (14*SmallDiam)/16;
    800800    myr.left   = xc - i+i/2;
    801801    myr.right  = xc + i/2;
     
    845845        }
    846846
    847         i = 10*SmallDiam/16;
     847        i = (10*SmallDiam)/16,1;
    848848        myr.left   = xc - i+i/2;
    849849        myr.right  = xc + i/2;
     
    853853        hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
    854854        hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
    855         Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
     855        Ellipse(dc,myr.left,myr.top,myr.right,myr.bottom);
    856856        SelectObject(dc, hbsave);
    857857        SelectObject(dc, hpsave);
     
    860860    if(uFlags & DFCS_CHECKED)
    861861    {
    862         i = 6*SmallDiam/16;
     862        i = (6*SmallDiam)/16;
    863863        i = i < 1 ? 1 : i;
    864864        myr.left   = xc - i+i/2;
     
    870870        hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
    871871        hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
    872         Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
     872        Ellipse(dc,myr.left,myr.top,myr.right,myr.bottom);
    873873        SelectObject(dc, hpsave);
    874874        SelectObject(dc, hbsave);
Note: See TracChangeset for help on using the changeset viewer.