Changeset 9370 for trunk/src/comctl32/progress.c
- Timestamp:
- Oct 29, 2002, 1:19:36 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/progress.c
r8382 r9370 1 /* 1 /* 2 2 * Progress control 3 3 * … … 18 18 * License along with this library; if not, write to the Free Software 19 19 * 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 * 20 33 */ 21 34 … … 43 56 #define LED_GAP 2 44 57 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 */ 63 static void PROGRESS_Invalidate( PROGRESS_INFO *infoPtr, INT old, INT new ) 64 { 65 LONG style = GetWindowLongW (infoPtr->Self, GWL_STYLE); 54 66 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 } 61 84 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 76 98 77 99 /*********************************************************************** … … 81 103 static LRESULT PROGRESS_Draw (PROGRESS_INFO *infoPtr, HDC hdc) 82 104 { 83 HBRUSH hbrBar ;105 HBRUSH hbrBar, hbrBk; 84 106 int rightBar, rightMost, ledWidth; 85 107 RECT rect; 86 108 DWORD dwStyle; 87 109 88 TRACE("(infoPtr=%p, hdc=% x)\n", infoPtr, hdc);110 TRACE("(infoPtr=%p, hdc=%p)\n", infoPtr, hdc); 89 111 90 112 /* get the required bar brush */ … … 94 116 hbrBar = CreateSolidBrush (infoPtr->ColorBar); 95 117 118 if (infoPtr->ColorBk == CLR_DEFAULT) 119 hbrBk = GetSysColorBrush(COLOR_3DFACE); 120 else 121 hbrBk = CreateSolidBrush(infoPtr->ColorBk); 122 96 123 /* get client rectangle */ 97 124 GetClientRect (infoPtr->Self, &rect); 98 125 FrameRect( hdc, &rect, hbrBk ); 99 126 InflateRect(&rect, -1, -1); 100 127 … … 104 131 /* compute extent of progress bar */ 105 132 if (dwStyle & PBS_VERTICAL) { 106 rightBar = rect.bottom - 133 rightBar = rect.bottom - 107 134 MulDiv (infoPtr->CurVal - infoPtr->MinVal, 108 135 rect.bottom - rect.top, … … 111 138 rightMost = rect.top; 112 139 } else { 113 rightBar = rect.left + 140 rightBar = rect.left + 114 141 MulDiv (infoPtr->CurVal - infoPtr->MinVal, 115 142 rect.right - rect.left, … … 120 147 121 148 /* 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 } 128 169 } else { 129 170 if (dwStyle & PBS_VERTICAL) { 130 while(rect.bottom > rightBar) { 171 while(rect.bottom > rightBar) { 131 172 rect.top = rect.bottom - ledWidth; 132 173 if (rect.top < rightMost) 133 174 rect.top = rightMost; 134 175 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; 136 181 } 182 rect.top = rightMost; 183 FillRect(hdc, &rect, hbrBk); 137 184 } else { 138 while(rect.left < rightBar) { 185 while(rect.left < rightBar) { 139 186 rect.right = rect.left + ledWidth; 140 187 if (rect.right > rightMost) 141 188 rect.right = rightMost; 142 189 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; 144 195 } 196 rect.right = rightMost; 197 FillRect(hdc, &rect, hbrBk); 145 198 } 146 199 } 147 200 148 201 /* 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); 151 204 152 205 return 0; … … 201 254 /* if nothing changes, simply return */ 202 255 if(infoPtr->MinVal == low && infoPtr->MaxVal == high) return res; 203 256 204 257 infoPtr->MinVal = low; 205 258 infoPtr->MaxVal = high; … … 211 264 * ProgressWindowProc 212 265 */ 213 static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, 266 static LRESULT WINAPI ProgressWindowProc(HWND hwnd, UINT message, 214 267 WPARAM wParam, LPARAM lParam) 215 268 { 216 269 PROGRESS_INFO *infoPtr; 217 270 218 TRACE("hwnd=% xmsg=%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); 219 272 220 273 infoPtr = (PROGRESS_INFO *)GetWindowLongW(hwnd, 0); 221 274 222 275 if (!infoPtr && message != WM_CREATE) 223 return DefWindowProcW( hwnd, message, wParam, lParam ); 276 return DefWindowProcW( hwnd, message, wParam, lParam ); 224 277 225 278 switch(message) { … … 229 282 dwExStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE); 230 283 dwExStyle |= WS_EX_STATICEDGE; 231 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_STATICEDGE);284 SetWindowLongW (hwnd, GWL_EXSTYLE, dwExStyle); 232 285 /* Force recalculation of a non-client area */ 233 286 SetWindowPos(hwnd, 0, 0, 0, 0, 0, … … 241 294 /* initialize the info struct */ 242 295 infoPtr->Self = hwnd; 243 infoPtr->MinVal = 0; 296 infoPtr->MinVal = 0; 244 297 infoPtr->MaxVal = 100; 245 infoPtr->CurVal = 0; 298 infoPtr->CurVal = 0; 246 299 infoPtr->Step = 10; 247 300 infoPtr->ColorBar = CLR_DEFAULT; 248 301 infoPtr->ColorBk = CLR_DEFAULT; 249 302 infoPtr->Font = 0; 250 TRACE("Progress Ctrl creation, hwnd=% 04x\n", hwnd);303 TRACE("Progress Ctrl creation, hwnd=%p\n", hwnd); 251 304 return 0; 252 305 } 253 306 254 307 case WM_DESTROY: 255 TRACE("Progress Ctrl destruction, hwnd=% 04x\n", hwnd);308 TRACE("Progress Ctrl destruction, hwnd=%p\n", hwnd); 256 309 COMCTL32_Free (infoPtr); 257 310 SetWindowLongW(hwnd, 0, 0); 258 311 return 0; 259 312 260 case WM_ERASEBKGND:261 PROGRESS_EraseBackground(infoPtr, wParam);262 return TRUE;263 264 313 case WM_GETFONT: 265 314 return (LRESULT)infoPtr->Font; 266 315 267 316 case WM_SETFONT: 268 return PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);317 return (LRESULT)PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam); 269 318 270 319 case WM_PAINT: 271 320 return PROGRESS_Paint (infoPtr, (HDC)wParam); 272 321 273 322 case PBM_DELTAPOS: 274 323 { 275 324 INT oldVal; 276 if(lParam) UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam);277 325 oldVal = infoPtr->CurVal; 278 326 if(wParam != 0) { 279 BOOL bErase;280 327 infoPtr->CurVal += (INT)wParam; 281 328 PROGRESS_CoercePos (infoPtr); 282 329 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 ); 285 331 } 286 332 return oldVal; … … 290 336 { 291 337 INT oldVal; 292 if (lParam) UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam);293 338 oldVal = infoPtr->CurVal; 294 339 if(oldVal != wParam) { 295 BOOL bErase;296 340 infoPtr->CurVal = (INT)wParam; 297 341 PROGRESS_CoercePos(infoPtr); 298 342 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 ); 301 344 } 302 345 return oldVal; 303 346 } 304 347 305 348 case PBM_SETRANGE: 306 if (wParam) UNKNOWN_PARAM(PBM_SETRANGE, wParam, lParam);307 349 return PROGRESS_SetRange (infoPtr, (int)LOWORD(lParam), (int)HIWORD(lParam)); 308 350 … … 310 352 { 311 353 INT oldStep; 312 if (lParam) UNKNOWN_PARAM(PBM_SETSTEP, wParam, lParam);313 354 oldStep = infoPtr->Step; 314 355 infoPtr->Step = (INT)wParam; … … 319 360 { 320 361 INT oldVal; 321 if (wParam || lParam) UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam); 322 oldVal = infoPtr->CurVal; 362 oldVal = infoPtr->CurVal; 323 363 infoPtr->CurVal += infoPtr->Step; 324 364 if(infoPtr->CurVal > infoPtr->MaxVal) … … 326 366 if(oldVal != infoPtr->CurVal) 327 367 { 328 BOOL bErase;329 368 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 ); 332 370 } 333 371 return oldVal; … … 336 374 case PBM_SETRANGE32: 337 375 return PROGRESS_SetRange (infoPtr, (int)wParam, (int)lParam); 338 376 339 377 case PBM_GETRANGE: 340 378 if (lParam) { … … 345 383 346 384 case PBM_GETPOS: 347 if (wParam || lParam) UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);348 385 return infoPtr->CurVal; 349 386 350 387 case PBM_SETBARCOLOR: 351 if (wParam) UNKNOWN_PARAM(PBM_SETBARCOLOR, wParam, lParam);352 388 infoPtr->ColorBar = (COLORREF)lParam; 353 389 InvalidateRect(hwnd, NULL, TRUE); … … 355 391 356 392 case PBM_SETBKCOLOR: 357 if (wParam) UNKNOWN_PARAM(PBM_SETBKCOLOR, wParam, lParam);358 393 infoPtr->ColorBk = (COLORREF)lParam; 359 394 InvalidateRect(hwnd, NULL, TRUE); 360 395 return 0; 361 396 362 default: 363 if ( message >= WM_USER)397 default: 398 if ((message >= WM_USER) && (message < WM_APP)) 364 399 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 } 367 402 } 368 403 … … 398 433 UnregisterClassW (PROGRESS_CLASSW, (HINSTANCE)NULL); 399 434 } 400
Note:
See TracChangeset
for help on using the changeset viewer.