Changeset 1203 for trunk/src/user32/combo.cpp
- Timestamp:
- Oct 8, 1999, 11:26:08 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/combo.cpp
r1184 r1203 1 /* $Id: combo.cpp,v 1. 3 1999-10-08 12:10:26cbratschi Exp $ */1 /* $Id: combo.cpp,v 1.4 1999-10-08 21:23:37 cbratschi Exp $ */ 2 2 /* 3 3 * Combo controls … … 7 7 * 8 8 * FIXME: roll up in Netscape 3.01. 9 * 10 * WINE version: 990923 9 11 */ 10 12 … … 655 657 RECT rectButton) 656 658 { 657 UINT x, y;658 BOOL bBool;659 HDC hMemDC;660 HBRUSH hPrevBrush;661 COLORREF oldTextColor, oldBkColor;662 663 659 if( lphc->wState & CBF_NOREDRAW ) 664 660 return; 665 661 666 hPrevBrush = SelectObject(hdc, GetSysColorBrush(COLOR_BTNFACE)); 667 668 /* 669 * Draw the button background 670 */ 671 PatBlt( hdc, 672 rectButton.left, 673 rectButton.top, 674 rectButton.right-rectButton.left, 675 rectButton.bottom-rectButton.top, 676 PATCOPY ); 677 678 bBool = lphc->wState & CBF_BUTTONDOWN; 679 if (bBool) 662 663 UINT buttonState = DFCS_SCROLLCOMBOBOX; 664 665 if (lphc->wState & CBF_BUTTONDOWN) 680 666 { 681 DrawEdge( hdc, &rectButton, EDGE_SUNKEN, BF_RECT );667 buttonState |= DFCS_PUSHED; 682 668 } 683 else 669 670 if (CB_DISABLED(lphc)) 684 671 { 685 DrawEdge( hdc, &rectButton, EDGE_RAISED, BF_RECT );672 buttonState |= DFCS_INACTIVE; 686 673 } 687 674 688 /* 689 * Remove the edge of the button from the rectangle 690 * and calculate the position of the bitmap. 691 */ 692 InflateRect( &rectButton, -2, -2); 693 694 x = (rectButton.left + rectButton.right - CBitWidth) >> 1; 695 y = (rectButton.top + rectButton.bottom - CBitHeight) >> 1; 696 697 698 hMemDC = CreateCompatibleDC( hdc ); 699 SelectObject( hMemDC, hComboBmp ); 700 oldTextColor = SetTextColor( hdc, GetSysColor(COLOR_BTNFACE) ); 701 oldBkColor = SetBkColor( hdc, CB_DISABLED(lphc) ? RGB(128,128,128) : 702 RGB(0,0,0) ); 703 BitBlt( hdc, x, y, CBitWidth, CBitHeight, hMemDC, 0, 0, SRCCOPY ); 704 SetBkColor( hdc, oldBkColor ); 705 SetTextColor( hdc, oldTextColor ); 706 DeleteDC( hMemDC ); 707 SelectObject( hdc, hPrevBrush ); 675 DrawFrameControl(hdc,&rectButton,DFC_SCROLL,buttonState); 708 676 } 709 677 … … 718 686 RECT rectEdit) 719 687 { 720 INT 721 LPSTR 688 INT id, size = 0; 689 LPSTR pText = NULL; 722 690 723 691 if( lphc->wState & CBF_NOREDRAW ) return; … … 729 697 { 730 698 size = SendMessageA( lphc->hWndLBox, LB_GETTEXTLEN, id, 0); 731 pText = (LPSTR)HeapAlloc( GetProcessHeap(), 0, size + 1); 732 if(pText) 733 { 734 SendMessageA( lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText ); 735 pText[size] = '\0'; /* just in case */ 736 } else return; 699 if( (pText = (char*)HeapAlloc( GetProcessHeap(), 0, size + 1)) != NULL ) 700 { 701 SendMessageA( lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText ); 702 pText[size] = '\0'; /* just in case */ 703 } else return; 737 704 } 738 705 739 706 if( lphc->wState & CBF_EDIT ) 740 707 { 741 742 743 708 if( CB_HASSTRINGS(lphc) ) SetWindowTextA( lphc->hWndEdit, pText ? pText : "" ); 709 if( lphc->wState & CBF_FOCUSED ) 710 SendMessageA( lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1)); 744 711 } 745 712 else /* paint text field ourselves */ 746 713 { 747 HBRUSH hPrevBrush = 0; 748 HDC hDC = hdc; 749 750 if( !hDC ) 751 { 752 hDC = GetDC(lphc->hwndself); 753 if (hDC) 754 { 755 HBRUSH hBrush = SendMessageA( lphc->owner, 756 WM_CTLCOLORLISTBOX, 757 hDC, lphc->hwndself ); 758 hPrevBrush = SelectObject( hDC, 759 (hBrush) ? hBrush : GetStockObject(WHITE_BRUSH) ); 760 } 761 } 762 if( hDC ) 763 { 764 UINT itemState; 765 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hDC, lphc->hFont) : 0; 766 767 /* 768 * Give ourselves some space. 769 */ 770 InflateRect( &rectEdit, -1, -1 ); 771 772 if ( (lphc->wState & CBF_FOCUSED) && 773 !(lphc->wState & CBF_DROPPED) ) 774 { 775 /* highlight */ 776 777 FillRect( hDC, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) ); 778 SetBkColor( hDC, GetSysColor( COLOR_HIGHLIGHT ) ); 779 SetTextColor( hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); 780 itemState = ODS_SELECTED | ODS_FOCUS; 781 } 782 else 783 itemState = 0; 784 785 if( CB_OWNERDRAWN(lphc) ) 786 { 787 DRAWITEMSTRUCT dis; 788 HRGN clipRegion; 789 790 /* 791 * Save the current clip region. 792 * To retrieve the clip region, we need to create one "dummy" 793 * clip region. 794 */ 795 clipRegion = CreateRectRgnIndirect(&rectEdit); 796 797 if (GetClipRgn(hDC, clipRegion)!=1) 798 { 799 DeleteObject(clipRegion); 800 clipRegion=(HRGN)NULL; 801 } 802 803 if ( GetWindowLongA(lphc->hwndself,GWL_STYLE) & WS_DISABLED ) 804 itemState |= ODS_DISABLED; 805 806 dis.CtlType = ODT_COMBOBOX; 807 dis.CtlID = GetWindowLongA(lphc->hwndself,GWL_ID); 808 dis.hwndItem = lphc->hwndself; 809 dis.itemAction = ODA_DRAWENTIRE; 810 dis.itemID = id; 811 dis.itemState = itemState; 812 dis.hDC = hDC; 813 dis.rcItem = rectEdit; 814 dis.itemData = SendMessageA( lphc->hWndLBox, LB_GETITEMDATA, 815 (WPARAM)id, 0 ); 816 817 /* 818 * Clip the DC and have the parent draw the item. 819 */ 820 IntersectClipRect(hDC, 821 rectEdit.left, rectEdit.top, 822 rectEdit.right, rectEdit.bottom); 823 824 SendMessageA(lphc->owner, WM_DRAWITEM, 825 GetWindowLongA(lphc->hwndself,GWL_ID), (LPARAM)&dis ); 826 827 /* 828 * Reset the clipping region. 829 */ 830 SelectClipRgn(hDC, clipRegion); 831 } 832 else 833 { 834 ExtTextOutA( hDC, 835 rectEdit.left + 1, 836 rectEdit.top + 1, 837 ETO_OPAQUE | ETO_CLIPPED, 838 &rectEdit, 839 pText ? pText : "" , size, NULL ); 840 841 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED)) 842 DrawFocusRect( hDC, &rectEdit ); 843 } 844 845 if( hPrevFont ) 846 SelectObject(hDC, hPrevFont ); 847 848 if( !hdc ) 849 { 850 if( hPrevBrush ) 851 SelectObject( hDC, hPrevBrush ); 852 853 ReleaseDC( lphc->hwndself, hDC ); 854 } 855 } 714 UINT itemState; 715 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0; 716 717 /* 718 * Give ourselves some space. 719 */ 720 InflateRect( &rectEdit, -1, -1 ); 721 722 if ( (lphc->wState & CBF_FOCUSED) && 723 !(lphc->wState & CBF_DROPPED) ) 724 { 725 /* highlight */ 726 727 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) ); 728 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) ); 729 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); 730 itemState = ODS_SELECTED | ODS_FOCUS; 731 } 732 else 733 itemState = 0; 734 735 if( CB_OWNERDRAWN(lphc) ) 736 { 737 DRAWITEMSTRUCT dis; 738 HRGN clipRegion; 739 DWORD dwStyle = GetWindowLongA(lphc->hwndself,GWL_STYLE); 740 741 /* 742 * Save the current clip region. 743 * To retrieve the clip region, we need to create one "dummy" 744 * clip region. 745 */ 746 clipRegion = CreateRectRgnIndirect(&rectEdit); 747 748 if (GetClipRgn(hdc, clipRegion)!=1) 749 { 750 DeleteObject(clipRegion); 751 clipRegion=(HRGN)NULL; 752 } 753 754 if ( dwStyle & WS_DISABLED ) 755 itemState |= ODS_DISABLED; 756 757 dis.CtlType = ODT_COMBOBOX; 758 dis.CtlID = GetWindowLongA(lphc->hwndself,GWL_ID); 759 dis.hwndItem = lphc->hwndself; 760 dis.itemAction = ODA_DRAWENTIRE; 761 dis.itemID = id; 762 dis.itemState = itemState; 763 dis.hDC = hdc; 764 dis.rcItem = rectEdit; 765 dis.itemData = SendMessageA( lphc->hWndLBox, LB_GETITEMDATA, 766 (WPARAM)id, 0 ); 767 768 /* 769 * Clip the DC and have the parent draw the item. 770 */ 771 IntersectClipRect(hdc, 772 rectEdit.left, rectEdit.top, 773 rectEdit.right, rectEdit.bottom); 774 775 SendMessageA(lphc->owner, WM_DRAWITEM, 776 GetWindowLongA(lphc->hwndself,GWL_ID), (LPARAM)&dis ); 777 778 /* 779 * Reset the clipping region. 780 */ 781 SelectClipRgn(hdc, clipRegion); 782 } 783 else 784 { 785 ExtTextOutA( hdc, 786 rectEdit.left + 1, 787 rectEdit.top + 1, 788 ETO_OPAQUE | ETO_CLIPPED, 789 &rectEdit, 790 pText ? pText : "" , size, NULL ); 791 792 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED)) 793 DrawFocusRect( hdc, &rectEdit ); 794 } 795 796 if( hPrevFont ) 797 SelectObject(hdc, hPrevFont ); 856 798 } 857 799 if (pText) 858 800 HeapFree( GetProcessHeap(), 0, pText ); 859 801 } 860 802 … … 885 827 886 828 /*********************************************************************** 829 * COMBO_PrepareColors 830 * 831 * This method will sent the appropriate WM_CTLCOLOR message to 832 * prepare and setup the colors for the combo's DC. 833 * 834 * It also returns the brush to use for the background. 835 */ 836 static HBRUSH COMBO_PrepareColors( 837 HWND hwnd, 838 LPHEADCOMBO lphc, 839 HDC hDC) 840 { 841 HBRUSH hBkgBrush; 842 843 /* 844 * Get the background brush for this control. 845 */ 846 if (CB_DISABLED(lphc)) 847 { 848 hBkgBrush = SendMessageA( lphc->owner, WM_CTLCOLORSTATIC, 849 hDC, lphc->hwndself ); 850 851 /* 852 * We have to change the text color since WM_CTLCOLORSTATIC will 853 * set it to the "enabled" color. This is the same behavior as the 854 * edit control 855 */ 856 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT)); 857 } 858 else 859 { 860 if (lphc->wState & CBF_EDIT) 861 { 862 hBkgBrush = SendMessageA( lphc->owner, WM_CTLCOLOREDIT, 863 hDC, lphc->hwndself ); 864 } 865 else 866 { 867 hBkgBrush = SendMessageA( lphc->owner, WM_CTLCOLORLISTBOX, 868 hDC, lphc->hwndself ); 869 } 870 } 871 872 /* 873 * Catch errors. 874 */ 875 if( !hBkgBrush ) 876 hBkgBrush = GetSysColorBrush(COLOR_WINDOW); 877 878 return hBkgBrush; 879 } 880 881 /*********************************************************************** 887 882 * COMBO_EraseBackground 888 883 */ … … 913 908 } 914 909 915 hBkgBrush = SendMessageA( lphc->owner, WM_CTLCOLORLISTBOX, 916 hDC, hwnd); 917 918 if( !hBkgBrush ) 919 hBkgBrush = GetStockObject(WHITE_BRUSH); 910 /* 911 * Retrieve the background brush 912 */ 913 hBkgBrush = COMBO_PrepareColors(hwnd, lphc, hDC); 920 914 921 915 FillRect(hDC, &clientRect, hBkgBrush); … … 943 937 HBRUSH hPrevBrush, hBkgBrush; 944 938 945 hBkgBrush = SendMessageA( lphc->owner, WM_CTLCOLORLISTBOX,946 hDC, lphc->hwndself );947 948 if( !hBkgBrush )949 hBkgBrush = GetStockObject(WHITE_BRUSH);939 /* 940 * Retrieve the background brush and select it in the 941 * DC. 942 */ 943 hBkgBrush = COMBO_PrepareColors(lphc->hwndself, lphc, hDC); 950 944 951 945 hPrevBrush = SelectObject( hDC, hBkgBrush ); … … 1082 1076 int i; 1083 1077 int nHeight; 1084 int nDroppedHeight ;1078 int nDroppedHeight,nTempDroppedHeight; 1085 1079 1086 1080 //TRACE("[%04x]: drop down\n", CB_HWND(lphc)); … … 1122 1116 of the items in the dropped list */ 1123 1117 1118 /* And Remove any extra space (Best Fit) */ 1124 1119 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top; 1125 1120 nItems = (int)SendMessageA (lphc->hWndLBox, LB_GETCOUNT, 0, 0); 1126 nHeight = COMBO_YBORDERGAP; 1121 nHeight = COMBO_YBORDERSIZE(); 1122 nTempDroppedHeight = 0; 1127 1123 for (i = 0; i < nItems; i++) 1128 1124 { 1129 1125 nHeight += (int)SendMessageA (lphc->hWndLBox, LB_GETITEMHEIGHT, i, 0); 1130 1126 1131 if (nHeight >= nDroppedHeight) 1127 /* Did we pass the limit of what can be displayed */ 1128 if (nHeight > nDroppedHeight) 1129 { 1132 1130 break; 1133 1131 } 1134 1135 if (nHeight < nDroppedHeight) 1136 nDroppedHeight = nHeight; 1132 nTempDroppedHeight = nHeight; 1133 } 1134 1135 nDroppedHeight = nTempDroppedHeight; 1137 1136 1138 1137 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom, … … 1177 1176 lphc->wState &= ~CBF_DROPPED; 1178 1177 ShowWindow( lphc->hWndLBox, SW_HIDE ); 1178 if(GetCapture() == lphc->hWndLBox) 1179 { 1180 ReleaseCapture(); 1181 } 1182 1179 1183 1180 1184 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) … … 1708 1712 } 1709 1713 ReleaseCapture(); 1714 SetCapture(lphc->hWndLBox); 1710 1715 } 1711 1716 … … 1852 1857 EnableWindow( lphc->hWndEdit, (BOOL)wParam ); 1853 1858 EnableWindow( lphc->hWndLBox, (BOOL)wParam ); 1859 1860 /* Force the control to repaint when the enabled state changes. */ 1861 InvalidateRect(CB_HWND(lphc), NULL, TRUE); 1854 1862 return TRUE; 1855 1863 case WM_SETREDRAW:
Note:
See TracChangeset
for help on using the changeset viewer.