Commit 94d5cd42 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

Remove PROGRESS_Refresh, always do InvalidateRect() to repaint.

Add WM_ERASEBKGND handler as in Windows. Be slightly smarter whether invalidate background or not. Always treat wParam as INT to not lose signed values.
parent 07869ec4
...@@ -34,12 +34,40 @@ typedef struct ...@@ -34,12 +34,40 @@ typedef struct
"(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam); "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
/*********************************************************************** /***********************************************************************
* PROGRESS_EraseBackground
*/
static void PROGRESS_EraseBackground(PROGRESS_INFO *infoPtr, WPARAM wParam)
{
RECT rect;
HBRUSH hbrBk;
HDC hdc = wParam ? (HDC)wParam : GetDC(infoPtr->Self);
/* get the required background brush */
if(infoPtr->ColorBk == CLR_DEFAULT)
hbrBk = GetSysColorBrush(COLOR_3DFACE);
else
hbrBk = CreateSolidBrush(infoPtr->ColorBk);
/* get client rectangle */
GetClientRect(infoPtr->Self, &rect);
/* draw the background */
FillRect(hdc, &rect, hbrBk);
/* delete background brush */
if(infoPtr->ColorBk != CLR_DEFAULT)
DeleteObject (hbrBk);
if(!wParam) ReleaseDC(infoPtr->Self, hdc);
}
/***********************************************************************
* PROGRESS_Draw * PROGRESS_Draw
* Draws the progress bar. * Draws the progress bar.
*/ */
static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc) static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
{ {
HBRUSH hbrBar, hbrBk; HBRUSH hbrBar;
int rightBar, rightMost, ledWidth; int rightBar, rightMost, ledWidth;
RECT rect; RECT rect;
DWORD dwStyle; DWORD dwStyle;
...@@ -52,18 +80,9 @@ static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc) ...@@ -52,18 +80,9 @@ static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
else else
hbrBar = CreateSolidBrush (infoPtr->ColorBar); hbrBar = CreateSolidBrush (infoPtr->ColorBar);
/* get the required background brush */
if (infoPtr->ColorBk == CLR_DEFAULT)
hbrBk = GetSysColorBrush (COLOR_3DFACE);
else
hbrBk = CreateSolidBrush (infoPtr->ColorBk);
/* get client rectangle */ /* get client rectangle */
GetClientRect (infoPtr->Self, &rect); GetClientRect (infoPtr->Self, &rect);
/* draw the background */
FillRect(hdc, &rect, hbrBk);
InflateRect(&rect, -1, -1); InflateRect(&rect, -1, -1);
/* get the window style */ /* get the window style */
...@@ -117,24 +136,9 @@ static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc) ...@@ -117,24 +136,9 @@ static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc)
if (infoPtr->ColorBar != CLR_DEFAULT) if (infoPtr->ColorBar != CLR_DEFAULT)
DeleteObject (hbrBar); DeleteObject (hbrBar);
/* delete background brush */
if (infoPtr->ColorBk != CLR_DEFAULT)
DeleteObject (hbrBk);
return 0; return 0;
} }
/***********************************************************************
* PROGRESS_Refresh
* Draw the progress bar. The background need not be erased.
*/
static LRESULT PROGRESS_Refresh (PROGRESS_INFO *infoPtr)
{
HDC hdc = GetDC (infoPtr->Self);
LRESULT res = PROGRESS_Draw (infoPtr, hdc);
ReleaseDC (infoPtr->Self, hdc);
return res;
}
/*********************************************************************** /***********************************************************************
* PROGRESS_Paint * PROGRESS_Paint
...@@ -173,7 +177,7 @@ static HFONT PROGRESS_SetFont (PROGRESS_INFO *infoPtr, HFONT hFont, BOOL bRedraw ...@@ -173,7 +177,7 @@ static HFONT PROGRESS_SetFont (PROGRESS_INFO *infoPtr, HFONT hFont, BOOL bRedraw
{ {
HFONT hOldFont = infoPtr->Font; HFONT hOldFont = infoPtr->Font;
infoPtr->Font = hFont; infoPtr->Font = hFont;
if (bRedraw) PROGRESS_Refresh (infoPtr); /* Since infoPtr->Font is not used, there is no need for repaint */
return hOldFont; return hOldFont;
} }
...@@ -184,12 +188,9 @@ static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high) ...@@ -184,12 +188,9 @@ static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high)
/* if nothing changes, simply return */ /* if nothing changes, simply return */
if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res; if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res;
/* if things are different, adjust values and repaint the control */
if (high <= low) high = low + 1;
infoPtr->MinVal = low; infoPtr->MinVal = low;
infoPtr->MaxVal = high; infoPtr->MaxVal = high;
PROGRESS_CoercePos(infoPtr); PROGRESS_CoercePos(infoPtr);
PROGRESS_Refresh (infoPtr);
return res; return res;
} }
...@@ -199,16 +200,19 @@ static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high) ...@@ -199,16 +200,19 @@ static DWORD PROGRESS_SetRange (PROGRESS_INFO *infoPtr, int low, int high)
static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam) WPARAM wParam, LPARAM lParam)
{ {
PROGRESS_INFO *infoPtr = (PROGRESS_INFO *)GetWindowLongW(hwnd, 0); PROGRESS_INFO *infoPtr;
DWORD dwExStyle;
UINT temp; TRACE("hwnd=%x msg=%04x wparam=%x lParam=%lx\n", hwnd, message, wParam, lParam);
infoPtr = (PROGRESS_INFO *)GetWindowLongW(hwnd, 0);
if (!infoPtr && message != WM_CREATE) if (!infoPtr && message != WM_CREATE)
return DefWindowProcW( hwnd, message, wParam, lParam ); return DefWindowProcW( hwnd, message, wParam, lParam );
switch(message) { switch(message) {
case WM_CREATE: case WM_CREATE:
dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE); {
DWORD dwExStyle = GetWindowLongW (hwnd, GWL_EXSTYLE);
dwExStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE); dwExStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE);
dwExStyle |= WS_EX_STATICEDGE; dwExStyle |= WS_EX_STATICEDGE;
SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_STATICEDGE); SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_STATICEDGE);
...@@ -232,6 +236,7 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, ...@@ -232,6 +236,7 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
infoPtr->Font = 0; infoPtr->Font = 0;
TRACE("Progress Ctrl creation, hwnd=%04x\n", hwnd); TRACE("Progress Ctrl creation, hwnd=%04x\n", hwnd);
return 0; return 0;
}
case WM_DESTROY: case WM_DESTROY:
TRACE("Progress Ctrl destruction, hwnd=%04x\n", hwnd); TRACE("Progress Ctrl destruction, hwnd=%04x\n", hwnd);
...@@ -240,8 +245,7 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, ...@@ -240,8 +245,7 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
return 0; return 0;
case WM_ERASEBKGND: case WM_ERASEBKGND:
/* pretend to erase it here, but we will do it in the paint PROGRESS_EraseBackground(infoPtr, wParam);
function to avoid flicker */
return TRUE; return TRUE;
case WM_GETFONT: case WM_GETFONT:
...@@ -254,44 +258,67 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, ...@@ -254,44 +258,67 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
return PROGRESS_Paint (infoPtr, (HDC)wParam); return PROGRESS_Paint (infoPtr, (HDC)wParam);
case PBM_DELTAPOS: case PBM_DELTAPOS:
{
INT oldVal;
if(lParam) UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam); if(lParam) UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam);
temp = infoPtr->CurVal; oldVal = infoPtr->CurVal;
if(wParam != 0) { if(wParam != 0) {
infoPtr->CurVal += (WORD)wParam; BOOL bErase;
infoPtr->CurVal += (INT)wParam;
PROGRESS_CoercePos (infoPtr); PROGRESS_CoercePos (infoPtr);
PROGRESS_Refresh (infoPtr); TRACE("PBM_DELTAPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
bErase = (oldVal > infoPtr->CurVal);
InvalidateRect(hwnd, NULL, bErase);
}
return oldVal;
} }
return temp;
case PBM_SETPOS: case PBM_SETPOS:
{
INT oldVal;
if (lParam) UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam); if (lParam) UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam);
temp = infoPtr->CurVal; oldVal = infoPtr->CurVal;
if(temp != wParam) { if(oldVal != wParam) {
infoPtr->CurVal = (WORD)wParam; BOOL bErase;
infoPtr->CurVal = (INT)wParam;
PROGRESS_CoercePos(infoPtr); PROGRESS_CoercePos(infoPtr);
PROGRESS_Refresh (infoPtr); TRACE("PBM_SETPOS: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
bErase = (oldVal > infoPtr->CurVal);
InvalidateRect(hwnd, NULL, bErase);
}
return oldVal;
} }
return temp;
case PBM_SETRANGE: case PBM_SETRANGE:
if (wParam) UNKNOWN_PARAM(PBM_SETRANGE, wParam, lParam); if (wParam) UNKNOWN_PARAM(PBM_SETRANGE, wParam, lParam);
return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam)); return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam));
case PBM_SETSTEP: case PBM_SETSTEP:
{
INT oldStep;
if (lParam) UNKNOWN_PARAM(PBM_SETSTEP, wParam, lParam); if (lParam) UNKNOWN_PARAM(PBM_SETSTEP, wParam, lParam);
temp = infoPtr->Step; oldStep = infoPtr->Step;
infoPtr->Step = (WORD)wParam; infoPtr->Step = (INT)wParam;
return temp; return oldStep;
}
case PBM_STEPIT: case PBM_STEPIT:
{
INT oldVal;
if (wParam || lParam) UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam); if (wParam || lParam) UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);
temp = infoPtr->CurVal; oldVal = infoPtr->CurVal;
infoPtr->CurVal += infoPtr->Step; infoPtr->CurVal += infoPtr->Step;
if(infoPtr->CurVal > infoPtr->MaxVal) if(infoPtr->CurVal > infoPtr->MaxVal)
infoPtr->CurVal = infoPtr->MinVal; infoPtr->CurVal = infoPtr->MinVal;
if(temp != infoPtr->CurVal) if(oldVal != infoPtr->CurVal)
PROGRESS_Refresh (infoPtr); {
return temp; BOOL bErase;
TRACE("PBM_STEPIT: current pos changed from %d to %d\n", oldVal, infoPtr->CurVal);
bErase = (oldVal > infoPtr->CurVal);
InvalidateRect(hwnd, NULL, bErase);
}
return oldVal;
}
case PBM_SETRANGE32: case PBM_SETRANGE32:
return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam); return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam);
...@@ -310,12 +337,14 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, ...@@ -310,12 +337,14 @@ static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message,
case PBM_SETBARCOLOR: case PBM_SETBARCOLOR:
if (wParam) UNKNOWN_PARAM(PBM_SETBARCOLOR, wParam, lParam); if (wParam) UNKNOWN_PARAM(PBM_SETBARCOLOR, wParam, lParam);
infoPtr->ColorBar = (COLORREF)lParam; infoPtr->ColorBar = (COLORREF)lParam;
return PROGRESS_Refresh (infoPtr); InvalidateRect(hwnd, NULL, TRUE);
return 0;
case PBM_SETBKCOLOR: case PBM_SETBKCOLOR:
if (wParam) UNKNOWN_PARAM(PBM_SETBKCOLOR, wParam, lParam); if (wParam) UNKNOWN_PARAM(PBM_SETBKCOLOR, wParam, lParam);
infoPtr->ColorBk = (COLORREF)lParam; infoPtr->ColorBk = (COLORREF)lParam;
return PROGRESS_Refresh (infoPtr); InvalidateRect(hwnd, NULL, TRUE);
return 0;
default: default:
if (message >= WM_USER) if (message >= WM_USER)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment