Ignore:
Timestamp:
Oct 29, 2002, 1:19:36 PM (23 years ago)
Author:
sandervl
Message:

Wine resync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comctl32/progress.c

    r8382 r9370  
    1 /*             
     1/*
    22 * Progress control
    33 *
     
    1818 * License along with this library; if not, write to the Free Software
    1919 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     20 *
     21 * NOTE
     22 *
     23 * This code was audited for completeness against the documented features
     24 * of Comctl32.dll version 6.0 on Sep. 9, 2002, by Dimitrie O. Paun.
     25 *
     26 * Unless otherwise noted, we belive this code to be complete, as per
     27 * the specification mentioned above.
     28 * If you discover missing features, or bugs, please note them below.
     29 *
     30 * TODO
     31 *   --support PBS_MARQUE
     32 *
    2033 */
    2134
     
    4356#define LED_GAP    2
    4457
    45 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(       \
    46    "Unknown parameter(s) for message " #msg            \
    47    "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
    48 
    49 /***********************************************************************
    50  * PROGRESS_EraseBackground
    51  */
    52 static void PROGRESS_EraseBackground(PROGRESS_INFO *infoPtr, WPARAM wParam)
    53 {
     58/***********************************************************************
     59 * PROGRESS_Invalidate
     60 *
     61 * Invalide the range between old and new pos.
     62 */
     63static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new )
     64{
     65    LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE);
    5466    RECT rect;
    55     HBRUSH hbrBk;
    56     HDC hdc = wParam ? (HDC)wParam : GetDC(infoPtr->Self);
    57 
    58     /* get the required background brush */
    59     if(infoPtr->ColorBk == CLR_DEFAULT)
    60         hbrBk = GetSysColorBrush(COLOR_3DFACE);
     67    int oldPos, newPos, ledWidth;
     68
     69    GetClientRect (infoPtr->Self, &rect);
     70    InflateRect(&rect, -1, -1);
     71
     72    if (style & PBS_VERTICAL)
     73    {
     74        oldPos = rect.bottom - MulDiv (old - infoPtr->MinVal, rect.bottom - rect.top,
     75                                       infoPtr->MaxVal - infoPtr->MinVal);
     76        newPos = rect.bottom - MulDiv (new - infoPtr->MinVal, rect.bottom - rect.top,
     77                                       infoPtr->MaxVal - infoPtr->MinVal);
     78        ledWidth = MulDiv (rect.right - rect.left, 2, 3);
     79        rect.top = min( oldPos, newPos );
     80        rect.bottom = max( oldPos, newPos );
     81        if (!(style & PBS_SMOOTH)) rect.top -= ledWidth;
     82        InvalidateRect( infoPtr->Self, &rect, oldPos < newPos );
     83    }
    6184    else
    62         hbrBk = CreateSolidBrush(infoPtr->ColorBk);
    63 
    64     /* get client rectangle */
    65     GetClientRect(infoPtr->Self, &rect);
    66 
    67     /* draw the background */
    68     FillRect(hdc, &rect, hbrBk);
    69 
    70     /* delete background brush */
    71     if(infoPtr->ColorBk != CLR_DEFAULT)
    72         DeleteObject (hbrBk);
    73 
    74     if(!wParam) ReleaseDC(infoPtr->Self, hdc);
    75 }
     85    {
     86        oldPos = rect.left + MulDiv (old - infoPtr->MinVal, rect.right - rect.left,
     87                                     infoPtr->MaxVal - infoPtr->MinVal);
     88        newPos = rect.left + MulDiv (new - infoPtr->MinVal, rect.right - rect.left,
     89                                     infoPtr->MaxVal - infoPtr->MinVal);
     90        ledWidth = MulDiv (rect.bottom - rect.top, 2, 3);
     91        rect.left = min( oldPos, newPos );
     92        rect.right = max( oldPos, newPos );
     93        if (!(style & PBS_SMOOTH)) rect.right += ledWidth;
     94        InvalidateRect( infoPtr->Self, &rect, oldPos > newPos );
     95    }
     96}
     97
    7698
    7799/***********************************************************************
     
    81103static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
    82104{
    83     HBRUSH hbrBar;
     105    HBRUSH hbrBar, hbrBk;
    84106    int rightBar, rightMost, ledWidth;
    85107    RECT rect;
    86108    DWORD dwStyle;
    87109
    88     TRACE("(infoPtr=%p, hdc=%x)\n", infoPtr, hdc);
     110    TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc);
    89111
    90112    /* get the required bar brush */
     
    94116        hbrBar = CreateSolidBrush (infoPtr->ColorBar);
    95117
     118    if (infoPtr->ColorBk == CLR_DEFAULT)
     119        hbrBk = GetSysColorBrush(COLOR_3DFACE);
     120    else
     121        hbrBk = CreateSolidBrush(infoPtr->ColorBk);
     122
    96123    /* get client rectangle */
    97124    GetClientRect (infoPtr->Self, &rect);
    98 
     125    FrameRect( hdc, &rect, hbrBk );
    99126    InflateRect(&rect, -1, -1);
    100127
     
    104131    /* compute extent of progress bar */
    105132    if (dwStyle & PBS_VERTICAL) {
    106         rightBar  = rect.bottom - 
     133        rightBar  = rect.bottom -
    107134                    MulDiv (infoPtr->CurVal - infoPtr->MinVal,
    108135                            rect.bottom - rect.top,
     
    111138        rightMost = rect.top;
    112139    } else {
    113         rightBar = rect.left + 
     140        rightBar = rect.left +
    114141                   MulDiv (infoPtr->CurVal - infoPtr->MinVal,
    115142                           rect.right - rect.left,
     
    120147
    121148    /* now draw the bar */
    122     if (dwStyle & PBS_SMOOTH) {
    123         if (dwStyle & PBS_VERTICAL)
    124             rect.top = rightBar;
    125         else
    126             rect.right = rightBar;
    127         FillRect(hdc, &rect, hbrBar);
     149    if (dwStyle & PBS_SMOOTH)
     150    {
     151        if (dwStyle & PBS_VERTICAL)
     152        {
     153            INT old_top = rect.top;
     154            rect.top = rightBar;
     155            FillRect(hdc, &rect, hbrBar);
     156            rect.bottom = rect.top;
     157            rect.top = old_top;
     158            FillRect(hdc, &rect, hbrBk);
     159        }
     160        else
     161        {
     162            INT old_right = rect.right;
     163            rect.right = rightBar;
     164            FillRect(hdc, &rect, hbrBar);
     165            rect.left = rect.right;
     166            rect.right = old_right;
     167            FillRect(hdc, &rect, hbrBk);
     168        }
    128169    } else {
    129170        if (dwStyle & PBS_VERTICAL) {
    130             while(rect.bottom > rightBar) { 
     171            while(rect.bottom > rightBar) {
    131172                rect.top = rect.bottom - ledWidth;
    132173                if (rect.top < rightMost)
    133174                    rect.top = rightMost;
    134175                FillRect(hdc, &rect, hbrBar);
    135                 rect.bottom = rect.top - LED_GAP;
     176                rect.bottom = rect.top;
     177                rect.top -= LED_GAP;
     178                if (rect.top <= rightBar) break;
     179                FillRect(hdc, &rect, hbrBk);
     180                rect.bottom = rect.top;
    136181            }
     182            rect.top = rightMost;
     183            FillRect(hdc, &rect, hbrBk);
    137184        } else {
    138             while(rect.left < rightBar) { 
     185            while(rect.left < rightBar) {
    139186                rect.right = rect.left + ledWidth;
    140187                if (rect.right > rightMost)
    141188                    rect.right = rightMost;
    142189                FillRect(hdc, &rect, hbrBar);
    143                 rect.left  = rect.right + LED_GAP;
     190                rect.left = rect.right;
     191                rect.right += LED_GAP;
     192                if (rect.right >= rightBar) break;
     193                FillRect(hdc, &rect, hbrBk);
     194                rect.left = rect.right;
    144195            }
     196            rect.right = rightMost;
     197            FillRect(hdc, &rect, hbrBk);
    145198        }
    146199    }
    147200
    148201    /* delete bar brush */
    149     if (infoPtr->ColorBar != CLR_DEFAULT)
    150         DeleteObject (hbrBar);
     202    if (infoPtr->ColorBar != CLR_DEFAULT) DeleteObject (hbrBar);
     203    if (infoPtr->ColorBk != CLR_DEFAULT) DeleteObject (hbrBk);
    151204
    152205    return 0;
     
    201254    /* if nothing changes, simply return */
    202255    if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res;
    203    
     256
    204257    infoPtr->MinVal = low;
    205258    infoPtr->MaxVal = high;
     
    211264 *           ProgressWindowProc
    212265 */
    213 static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, 
     266static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
    214267                                  WPARAM wParam, LPARAM lParam)
    215268{
    216269    PROGRESS_INFO *infoPtr;
    217270
    218     TRACE("hwnd=%x msg=%04x wparam=%x lParam=%lx\n", hwnd, message, wParam, lParam);
     271    TRACE("hwnd=%p msg=%04x wparam=%x lParam=%lx\n", hwnd, message, wParam, lParam);
    219272
    220273    infoPtr = (PROGRESS_INFO *)GetWindowLongW(hwnd, 0);
    221274
    222275    if (!infoPtr && message != WM_CREATE)
    223         return DefWindowProcW( hwnd, message, wParam, lParam ); 
     276        return DefWindowProcW( hwnd, message, wParam, lParam );
    224277
    225278    switch(message) {
     
    229282        dwExStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE);
    230283        dwExStyle |= WS_EX_STATICEDGE;
    231         SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_STATICEDGE);
     284        SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle);
    232285        /* Force recalculation of a non-client area */
    233286        SetWindowPos(hwnd, 0, 0, 0, 0, 0,
     
    241294        /* initialize the info struct */
    242295        infoPtr->Self = hwnd;
    243         infoPtr->MinVal = 0; 
     296        infoPtr->MinVal = 0;
    244297        infoPtr->MaxVal = 100;
    245         infoPtr->CurVal = 0; 
     298        infoPtr->CurVal = 0;
    246299        infoPtr->Step = 10;
    247300        infoPtr->ColorBar = CLR_DEFAULT;
    248301        infoPtr->ColorBk = CLR_DEFAULT;
    249302        infoPtr->Font = 0;
    250         TRACE("Progress Ctrl creation, hwnd=%04x\n", hwnd);
     303        TRACE("Progress Ctrl creation, hwnd=%p\n", hwnd);
    251304        return 0;
    252305    }
    253    
     306
    254307    case WM_DESTROY:
    255         TRACE("Progress Ctrl destruction, hwnd=%04x\n", hwnd);
     308        TRACE("Progress Ctrl destruction, hwnd=%p\n", hwnd);
    256309        COMCTL32_Free (infoPtr);
    257310        SetWindowLongW(hwnd, 0, 0);
    258311        return 0;
    259312
    260     case WM_ERASEBKGND:
    261         PROGRESS_EraseBackground(infoPtr, wParam);
    262         return TRUE;
    263        
    264313    case WM_GETFONT:
    265314        return (LRESULT)infoPtr->Font;
    266315
    267316    case WM_SETFONT:
    268         return PROGRESS_SetFont (infoPtr, (HFONT)wParam, (BOOL)lParam);
     317        return (LRESULT)PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
    269318
    270319    case WM_PAINT:
    271320        return PROGRESS_Paint (infoPtr, (HDC)wParam);
    272    
     321
    273322    case PBM_DELTAPOS:
    274323    {
    275324        INT oldVal;
    276         if(lParam) UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam);
    277325        oldVal = infoPtr->CurVal;
    278326        if(wParam != 0) {
    279             BOOL bErase;
    280327            infoPtr->CurVal += (INT)wParam;
    281328            PROGRESS_CoercePos (infoPtr);
    282329            TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
    283             bErase = (oldVal > infoPtr->CurVal);
    284             InvalidateRect(hwnd, NULL, bErase);
     330            PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
    285331        }
    286332        return oldVal;
     
    290336    {
    291337        INT oldVal;
    292         if (lParam) UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam);
    293338        oldVal = infoPtr->CurVal;
    294339        if(oldVal != wParam) {
    295             BOOL bErase;
    296340            infoPtr->CurVal = (INT)wParam;
    297341            PROGRESS_CoercePos(infoPtr);
    298342            TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
    299             bErase = (oldVal > infoPtr->CurVal);
    300             InvalidateRect(hwnd, NULL, bErase);
     343            PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
    301344        }
    302345        return oldVal;
    303346    }
    304      
     347
    305348    case PBM_SETRANGE:
    306         if (wParam) UNKNOWN_PARAM(PBM_SETRANGE, wParam, lParam);
    307349        return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam));
    308350
     
    310352    {
    311353        INT oldStep;
    312         if (lParam) UNKNOWN_PARAM(PBM_SETSTEP, wParam, lParam);
    313354        oldStep = infoPtr->Step;
    314355        infoPtr->Step = (INT)wParam;
     
    319360    {
    320361        INT oldVal;
    321         if (wParam || lParam) UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);
    322         oldVal = infoPtr->CurVal;   
     362        oldVal = infoPtr->CurVal;
    323363        infoPtr->CurVal += infoPtr->Step;
    324364        if(infoPtr->CurVal > infoPtr->MaxVal)
     
    326366        if(oldVal != infoPtr->CurVal)
    327367        {
    328             BOOL bErase;
    329368            TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
    330             bErase = (oldVal > infoPtr->CurVal);
    331             InvalidateRect(hwnd, NULL, bErase);
     369            PROGRESS_Invalidate( infoPtr, oldVal, infoPtr->CurVal );
    332370        }
    333371        return oldVal;
     
    336374    case PBM_SETRANGE32:
    337375        return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam);
    338    
     376
    339377    case PBM_GETRANGE:
    340378        if (lParam) {
     
    345383
    346384    case PBM_GETPOS:
    347         if (wParam || lParam) UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);
    348385        return infoPtr->CurVal;
    349386
    350387    case PBM_SETBARCOLOR:
    351         if (wParam) UNKNOWN_PARAM(PBM_SETBARCOLOR, wParam, lParam);
    352388        infoPtr->ColorBar = (COLORREF)lParam;
    353389        InvalidateRect(hwnd, NULL, TRUE);
     
    355391
    356392    case PBM_SETBKCOLOR:
    357         if (wParam) UNKNOWN_PARAM(PBM_SETBKCOLOR, wParam, lParam);
    358393        infoPtr->ColorBk = (COLORREF)lParam;
    359394        InvalidateRect(hwnd, NULL, TRUE);
    360395        return 0;
    361396
    362     default: 
    363         if (message >= WM_USER)
     397    default:
     398        if ((message >= WM_USER) && (message < WM_APP))
    364399            ERR("unknown msg %04x wp=%04x lp=%08lx\n", message, wParam, lParam );
    365         return DefWindowProcW( hwnd, message, wParam, lParam ); 
    366     } 
     400        return DefWindowProcW( hwnd, message, wParam, lParam );
     401    }
    367402}
    368403
     
    398433    UnregisterClassW (PROGRESS_CLASSW, (HINSTANCE)NULL);
    399434}
    400 
Note: See TracChangeset for help on using the changeset viewer.