Changeset 500 for trunk/src/user32/new/button.cpp
- Timestamp:
- Aug 15, 1999, 9:11:02 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/new/button.cpp
r402 r500 1 /* $Id: button.cpp,v 1.1 0 1999-07-27 16:14:22cbratschi Exp $ */1 /* $Id: button.cpp,v 1.11 1999-08-15 19:11:00 cbratschi Exp $ */ 2 2 /* File: button.cpp -- Button type widgets 3 3 * … … 31 31 static void OB_Paint(HWND hwnd,HDC hDC,WORD action); 32 32 static void BUTTON_CheckAutoRadioButton(HWND hwnd); 33 static void BUTTON_DrawPushButton(HWND hwnd,HDC hDC,WORD action,BOOL pushedState); 33 34 static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam); 34 35 … … 181 182 { 182 183 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 183 184 switch(dwStyle & 0x0f) 185 { 186 case BS_RADIOBUTTON: 187 case BS_AUTORADIOBUTTON: 188 case BS_OWNERDRAW: 189 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),BN_DOUBLECLICKED),hwnd); 190 break; 191 192 default: 193 BUTTON_LButtonDown(hwnd,wParam,lParam); 194 break; 195 } 184 DWORD style = dwStyle & 0x0f; 185 186 if(dwStyle & BS_NOTIFY || style == BS_RADIOBUTTON || 187 style == BS_USERBUTTON || style == BS_OWNERDRAW) 188 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),BN_DOUBLECLICKED),hwnd); 189 else BUTTON_LButtonDown(hwnd,wParam,lParam); 196 190 197 191 return 0; … … 200 194 static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam) 201 195 { 196 SetCapture(hwnd); 197 SetFocus(hwnd); 202 198 SendMessageA(hwnd,BM_SETSTATE,TRUE,0); 203 SetFocus(hwnd);204 SetCapture(hwnd);205 199 206 200 return 0; … … 355 349 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f; 356 350 357 infoPtr->state |= BUTTON_HASFOCUS; 358 if (style == BS_AUTORADIOBUTTON) 359 { 360 SendMessageA(hwnd,BM_SETCHECK,1,0); 361 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),BN_CLICKED),hwnd); 362 } else if (style == BS_RADIOBUTTON) 363 { 351 if ((style == BS_AUTORADIOBUTTON || style == BS_RADIOBUTTON) && 352 (GetCapture() != hwnd) && !(SendMessageA(hwnd,BM_GETCHECK,0,0) & BST_CHECKED)) 353 { 354 /* The notification is sent when the button (BS_AUTORADIOBUTTON) 355 is unckecked and the focus was not given by a mouse click. */ 356 if (style == BS_AUTORADIOBUTTON) SendMessageA(hwnd,BM_SETCHECK,TRUE,0); 364 357 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),BN_CLICKED),hwnd); 365 358 } 366 359 360 infoPtr->state |= BUTTON_HASFOCUS; 367 361 PAINT_BUTTON(hwnd,style,ODA_FOCUS); 368 362 … … 424 418 HANDLE oldHbitmap = infoPtr->hImage; 425 419 426 if (dwStyle & BS_BITMAP ) infoPtr->hImage = (HANDLE)lParam;420 if (dwStyle & BS_BITMAP || dwStyle & BS_ICON) infoPtr->hImage = (HANDLE)lParam; 427 421 428 422 return oldHbitmap; … … 433 427 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd); 434 428 435 return infoPtr->hImage; 429 switch(wParam) 430 { 431 case IMAGE_BITMAP: 432 return (HBITMAP)infoPtr->hImage; 433 case IMAGE_ICON: 434 return (HICON)infoPtr->hImage; 435 default: 436 return NULL; 437 } 436 438 } 437 439 … … 600 602 * Push Button Functions 601 603 */ 602 603 static void PB_Paint(HWND hwnd,HDC hDC,WORD action) 604 { 605 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd); 606 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 607 RECT rc; 604 static void PB_Paint( HWND hwnd, HDC hDC, WORD action ) 605 { 606 BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd); 607 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED); 608 609 /* 610 * Delegate this to the more generic pushbutton painting 611 * method. 612 */ 613 BUTTON_DrawPushButton(hwnd, 614 hDC, 615 action, 616 bHighLighted); 617 } 618 619 /********************************************************************** 620 * This method will actually do the drawing of the pushbutton 621 * depending on it's state and the pushedState parameter. 622 */ 623 static void BUTTON_DrawPushButton( 624 HWND hwnd, 625 HDC hDC, 626 WORD action, 627 BOOL pushedState ) 628 { 629 RECT rc, focus_rect; 608 630 HPEN hOldPen; 609 631 HBRUSH hOldBrush; 632 BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd); 633 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 610 634 int xBorderOffset, yBorderOffset; 611 635 xBorderOffset = yBorderOffset = 0; … … 613 637 char* text; 614 638 615 GetClientRect( hwnd,&rc );639 GetClientRect( hwnd, &rc ); 616 640 617 641 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */ 618 642 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont ); 619 SendMessageA(GetParent(hwnd),WM_CTLCOLORBTN,hDC,hwnd); 620 643 BUTTON_SEND_CTLCOLOR( hwnd, hDC ); 621 644 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME)); 622 645 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); 623 646 SetBkMode(hDC, TRANSPARENT); 624 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);625 /* if (action == ODA_DRAWENTIRE)*/626 {627 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );628 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );629 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );630 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));631 }632 InflateRect( &rc, -1, -1 );633 647 634 648 if ((dwStyle & 0x000f) == BS_DEFPUSHBUTTON) 635 649 { 636 650 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); 637 InflateRect( &rc, -1, -1 ); 638 } 639 640 if (infoPtr->state & BUTTON_HIGHLIGHTED) 641 { 642 /* draw button shadow: */ 643 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW)); 644 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY ); 645 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY ); 646 rc.left += 2; /* To position the text down and right */ 647 rc.top += 2; 648 } else { 649 rc.right++, rc.bottom++; 650 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT ); 651 652 /* To place de bitmap correctly */ 653 xBorderOffset += GetSystemMetrics(SM_CXEDGE); 654 yBorderOffset += GetSystemMetrics(SM_CYEDGE); 655 656 rc.right--, rc.bottom--; 657 } 658 659 /* draw button label, if any: */ 651 InflateRect( &rc, -1, -1 ); 652 } 653 654 UINT uState = DFCS_BUTTONPUSH; 655 656 if (pushedState) 657 { 658 if ( (dwStyle & 0x000f) == BS_DEFPUSHBUTTON ) 659 uState |= DFCS_FLAT; 660 else 661 uState |= DFCS_PUSHED; 662 } 663 664 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState ); 665 InflateRect( &rc, -2, -2 ); 666 667 focus_rect = rc; 668 669 if (pushedState) 670 { 671 rc.left += 2; /* To position the text down and right */ 672 rc.top += 2; 673 } 674 675 676 /* draw button label, if any: 677 * 678 * In win9x we don't show text if there is a bitmap or icon. 679 * I don't know about win31 so I leave it as it was for win31. 680 * Dennis Björklund 12 Jul, 99 681 */ 660 682 textLen = GetWindowTextLengthA(hwnd); 661 if (textLen > 0 )683 if (textLen > 0 && (!(dwStyle & (BS_ICON|BS_BITMAP)))) 662 684 { 663 685 LOGBRUSH lb; … … 668 690 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb ); 669 691 if (dwStyle & WS_DISABLED && 670 GetSysColor(COLOR_GRAYTEXT) ==lb.lbColor)692 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor) 671 693 /* don't write gray text on gray background */ 672 694 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,text, 673 695 DT_CENTER | DT_VCENTER ); 674 696 else 675 697 { … … 679 701 DrawTextA( hDC, text, -1, &rc, 680 702 DT_SINGLELINE | DT_CENTER | DT_VCENTER ); 681 /* do we have the focus? */ 682 if (infoPtr->state & BUTTON_HASFOCUS) 683 { 684 RECT r = { 0, 0, 0, 0 }; 685 INT xdelta, ydelta; 686 687 DrawTextA( hDC, text, -1, &r, 688 DT_SINGLELINE | DT_CALCRECT ); 689 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2; 690 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2; 691 if (xdelta < 0) xdelta = 0; 692 if (ydelta < 0) ydelta = 0; 693 InflateRect( &rc, -xdelta, -ydelta ); 694 DrawFocusRect( hDC, &rc ); 695 } 703 /* do we have the focus? 704 * Win9x draws focus last with a size prop. to the button 705 */ 696 706 } 697 707 free(text); 698 708 } 699 700 if((dwStyle & BS_BITMAP) && (infoPtr->hImage != NULL)) 701 { 702 BITMAP bm; 703 HDC hdcMem; 704 int yOffset, xOffset, imageWidth, imageHeight; 705 706 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm); 707 708 /* Center the bitmap */ 709 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - bm.bmWidth ) / 2; 710 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - bm.bmHeight ) / 2; 711 712 imageWidth = bm.bmWidth; 713 imageHeight = bm.bmHeight; 714 715 /* If the image is to big for the button */ 716 if (xOffset < 0) 709 if ( ((dwStyle & BS_ICON) || (dwStyle & BS_BITMAP) ) && 710 (infoPtr->hImage != NULL) ) 711 { 712 int yOffset, xOffset; 713 int imageWidth, imageHeight; 714 715 /* 716 * We extract the size of the image from the handle. 717 */ 718 if (dwStyle & BS_ICON) 719 { 720 ICONINFO iconInfo; 721 BITMAP bm; 722 723 GetIconInfo((HICON)infoPtr->hImage, &iconInfo); 724 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm); 725 726 imageWidth = bm.bmWidth; 727 imageHeight = bm.bmHeight; 728 729 DeleteObject(iconInfo.hbmColor); 730 DeleteObject(iconInfo.hbmMask); 731 732 } 733 else 734 { 735 BITMAP bm; 736 737 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm); 738 739 imageWidth = bm.bmWidth; 740 imageHeight = bm.bmHeight; 741 } 742 743 /* Center the bitmap */ 744 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2; 745 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2; 746 747 /* If the image is too big for the button then create a region*/ 748 if(xOffset < 0 || yOffset < 0) 749 { 750 HRGN hBitmapRgn = NULL; 751 hBitmapRgn = CreateRectRgn( 752 rc.left + xBorderOffset, rc.top +yBorderOffset, 753 rc.right - xBorderOffset, rc.bottom - yBorderOffset); 754 SelectClipRgn(hDC, hBitmapRgn); 755 DeleteObject(hBitmapRgn); 756 } 757 758 /* Let minimum 1 space from border */ 759 xOffset++, yOffset++; 760 761 /* 762 * Draw the image now. 763 */ 764 if (dwStyle & BS_ICON) 765 { 766 DrawIcon(hDC, 767 rc.left + xOffset, rc.top + yOffset, 768 (HICON)infoPtr->hImage); 769 } 770 else 717 771 { 718 imageWidth = rc.right - rc.left - 2*xBorderOffset -1; 719 xOffset = xBorderOffset; 772 HDC hdcMem; 773 774 hdcMem = CreateCompatibleDC (hDC); 775 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage); 776 BitBlt(hDC, 777 rc.left + xOffset, 778 rc.top + yOffset, 779 imageWidth, imageHeight, 780 hdcMem, 0, 0, SRCCOPY); 781 782 DeleteDC (hdcMem); 783 } 784 785 if(xOffset < 0 || yOffset < 0) 786 { 787 SelectClipRgn(hDC, NULL); 720 788 } 721 722 if (yOffset < 0) 723 { 724 imageHeight = rc.bottom - rc.top - 2*yBorderOffset -1; 725 yOffset = yBorderOffset; 726 } 727 728 /* Let minimum 1 space from border */ 729 xOffset++, yOffset++; 730 731 hdcMem = CreateCompatibleDC (hDC); 732 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage); 733 BitBlt(hDC, rc.left + xOffset, 734 rc.top + yOffset, 735 imageWidth, imageHeight, 736 hdcMem, 0, 0, SRCCOPY); 737 738 DeleteDC (hdcMem); 739 } 789 } 790 791 if (infoPtr->state & BUTTON_HASFOCUS) 792 { 793 InflateRect( &focus_rect, -1, -1 ); 794 DrawFocusRect( hDC, &focus_rect ); 795 } 796 740 797 741 798 SelectObject( hDC, hOldPen ); 742 799 SelectObject( hDC, hOldBrush ); 743 800 } 744 745 801 746 802 /********************************************************************** … … 812 868 char* text = NULL; 813 869 870 /* 871 * if the button has a bitmap/icon, draw a normal pushbutton 872 * instead of a radion button. 873 */ 874 if (infoPtr->hImage!=NULL) 875 { 876 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) || 877 (infoPtr->state & BUTTON_CHECKED)); 878 879 BUTTON_DrawPushButton(hwnd, 880 hDC, 881 action, 882 bHighLighted); 883 return; 884 } 885 814 886 textLen = 0; 815 887 GetClientRect(hwnd, &client); … … 1019 1091 dis.itemData = 0; 1020 1092 GetClientRect( hwnd, &dis.rcItem ); 1093 1094 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) ); 1095 FillRect( hDC, &dis.rcItem, GetSysColorBrush( COLOR_BTNFACE ) ); 1096 1021 1097 SendMessageA( GetParent(hwnd), WM_DRAWITEM, 1022 1098 GetWindowLongA(hwnd,GWL_ID), (LPARAM)&dis );
Note:
See TracChangeset
for help on using the changeset viewer.