Ignore:
Timestamp:
Oct 8, 1999, 11:26:08 PM (26 years ago)
Author:
cbratschi
Message:

merged with WINE, other fixes

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:26 cbratschi Exp $ */
     1/* $Id: combo.cpp,v 1.4 1999-10-08 21:23:37 cbratschi Exp $ */
    22/*
    33 * Combo controls
     
    77 *
    88 * FIXME: roll up in Netscape 3.01.
     9 *
     10 * WINE version: 990923
    911 */
    1012
     
    655657  RECT        rectButton)
    656658{
    657     UINT        x, y;
    658     BOOL        bBool;
    659     HDC       hMemDC;
    660     HBRUSH    hPrevBrush;
    661     COLORREF    oldTextColor, oldBkColor;
    662 
    663659    if( lphc->wState & CBF_NOREDRAW )
    664660      return;
    665661
    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)
    680666    {
    681         DrawEdge( hdc, &rectButton, EDGE_SUNKEN, BF_RECT );
     667      buttonState |= DFCS_PUSHED;
    682668    }
    683     else
     669
     670    if (CB_DISABLED(lphc))
    684671    {
    685         DrawEdge( hdc, &rectButton, EDGE_RAISED, BF_RECT );
     672      buttonState |= DFCS_INACTIVE;
    686673    }
    687674
    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);                   
    708676}
    709677
     
    718686  RECT        rectEdit)
    719687{
    720    INT  id, size = 0;
    721    LPSTR        pText = NULL;
     688   INT  id, size = 0;
     689   LPSTR        pText = NULL;
    722690
    723691   if( lphc->wState & CBF_NOREDRAW ) return;
     
    729697   {
    730698        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;
    737704   }
    738705
    739706   if( lphc->wState & CBF_EDIT )
    740707   {
    741         if( CB_HASSTRINGS(lphc) ) SetWindowTextA( lphc->hWndEdit, pText ? pText : "" );
    742         if( lphc->wState & CBF_FOCUSED )
    743             SendMessageA( lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
     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));
    744711   }
    745712   else /* paint text field ourselves */
    746713   {
    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 );
    856798   }
    857799   if (pText)
    858         HeapFree( GetProcessHeap(), 0, pText );
     800        HeapFree( GetProcessHeap(), 0, pText );
    859801}
    860802
     
    885827
    886828/***********************************************************************
     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 */
     836static 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/***********************************************************************
    887882 *           COMBO_EraseBackground
    888883 */
     
    913908  }
    914909
    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);
    920914
    921915  FillRect(hDC, &clientRect, hBkgBrush);
     
    943937      HBRUSH    hPrevBrush, hBkgBrush;
    944938
    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);
    950944
    951945      hPrevBrush = SelectObject( hDC, hBkgBrush );
     
    10821076   int i;
    10831077   int nHeight;
    1084    int nDroppedHeight;
     1078   int nDroppedHeight,nTempDroppedHeight;
    10851079
    10861080   //TRACE("[%04x]: drop down\n", CB_HWND(lphc));
     
    11221116     of the items in the dropped list */
    11231117
     1118  /* And Remove any extra space (Best Fit) */
    11241119   nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
    11251120   nItems = (int)SendMessageA (lphc->hWndLBox, LB_GETCOUNT, 0, 0);
    1126    nHeight = COMBO_YBORDERGAP;
     1121   nHeight = COMBO_YBORDERSIZE();
     1122   nTempDroppedHeight = 0;
    11271123   for (i = 0; i < nItems; i++)
    11281124   {
    11291125     nHeight += (int)SendMessageA (lphc->hWndLBox, LB_GETITEMHEIGHT, i, 0);
    11301126
    1131      if (nHeight >= nDroppedHeight)
     1127     /* Did we pass the limit of what can be displayed */
     1128     if (nHeight > nDroppedHeight)
     1129     {
    11321130       break;
    11331131   }
    1134 
    1135    if (nHeight < nDroppedHeight)
    1136       nDroppedHeight = nHeight;
     1132     nTempDroppedHeight = nHeight;
     1133   }
     1134
     1135   nDroppedHeight = nTempDroppedHeight;
    11371136
    11381137   SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
     
    11771176           lphc->wState &= ~CBF_DROPPED;
    11781177           ShowWindow( lphc->hWndLBox, SW_HIDE );
     1178           if(GetCapture() == lphc->hWndLBox)
     1179           {
     1180               ReleaseCapture();
     1181           }
     1182
    11791183
    11801184           if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
     
    17081712       }
    17091713       ReleaseCapture();
     1714       SetCapture(lphc->hWndLBox);
    17101715   }
    17111716
     
    18521857                    EnableWindow( lphc->hWndEdit, (BOOL)wParam );
    18531858                EnableWindow( lphc->hWndLBox, (BOOL)wParam );
     1859
     1860                /* Force the control to repaint when the enabled state changes. */
     1861                InvalidateRect(CB_HWND(lphc), NULL, TRUE);
    18541862                return  TRUE;
    18551863        case WM_SETREDRAW:
Note: See TracChangeset for help on using the changeset viewer.