4 * Copyright 1997 Dimitrie O. Paun
7 * - I do not know what to to on WM_[SG]ET_FONT
18 /* Control configuration constants */
24 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(progress, \
25 "Unknown parameter(s) for message " #msg \
26 "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
28 #define PROGRESS_GetInfoPtr(wndPtr) ((PROGRESS_INFO *)wndPtr->wExtra[0])
31 /***********************************************************************
33 * Draw the arrows. The background need not be erased.
34 * If dc!=0, it draws on it
36 static void PROGRESS_Paint(WND *wndPtr, HDC32 dc)
38 PROGRESS_INFO *infoPtr = PROGRESS_GetInfoPtr(wndPtr);
39 HBRUSH32 hbrBar, hbrBk;
40 int rightBar, rightMost, ledWidth;
45 TRACE(progress, "paint pos=%d min=%d, max=%d\n",
46 infoPtr->CurVal, infoPtr->MinVal, infoPtr->MaxVal);
49 hdc = dc==0 ? BeginPaint32(wndPtr->hwndSelf, &ps) : dc;
51 /* get the required bar brush */
52 if (infoPtr->ColorBar == CLR_DEFAULT)
53 hbrBar = GetSysColorBrush32(COLOR_HIGHLIGHT);
55 hbrBar = CreateSolidBrush32 (infoPtr->ColorBar);
57 /* get the required background brush */
58 if (infoPtr->ColorBk == CLR_DEFAULT)
59 hbrBk = GetSysColorBrush32 (COLOR_3DFACE);
61 hbrBk = CreateSolidBrush32 (infoPtr->ColorBk);
63 /* get rect for the bar, adjusted for the border */
64 GetClientRect32 (wndPtr->hwndSelf, &rect);
67 DrawEdge32(hdc, &rect, BDR_SUNKENOUTER, BF_RECT|BF_ADJUST);
68 FillRect32(hdc, &rect, hbrBk);
70 rect.left++; rect.right--; rect.top++; rect.bottom--;
72 /* compute extent of progress bar */
73 if (wndPtr->dwStyle & PBS_VERTICAL)
75 rightBar = rect.bottom -
76 MulDiv32(infoPtr->CurVal-infoPtr->MinVal,
77 rect.bottom - rect.top,
78 infoPtr->MaxVal-infoPtr->MinVal);
79 ledWidth = MulDiv32 ((rect.right - rect.left), 2, 3);
84 rightBar = rect.left +
85 MulDiv32(infoPtr->CurVal-infoPtr->MinVal,
86 rect.right - rect.left,
87 infoPtr->MaxVal-infoPtr->MinVal);
88 ledWidth = MulDiv32 ((rect.bottom - rect.top), 2, 3);
89 rightMost = rect.right;
92 /* now draw the bar */
93 if (wndPtr->dwStyle & PBS_SMOOTH)
95 if (wndPtr->dwStyle & PBS_VERTICAL)
98 rect.right = rightBar;
99 FillRect32(hdc, &rect, hbrBar);
103 if (wndPtr->dwStyle & PBS_VERTICAL)
104 while(rect.bottom > rightBar) {
105 rect.top = rect.bottom-ledWidth;
106 if (rect.top < rightMost)
107 rect.top = rightMost;
108 FillRect32(hdc, &rect, hbrBar);
109 rect.bottom = rect.top-LED_GAP;
112 while(rect.left < rightBar) {
113 rect.right = rect.left+ledWidth;
114 if (rect.right > rightMost)
115 rect.right = rightMost;
116 FillRect32(hdc, &rect, hbrBar);
117 rect.left = rect.right+LED_GAP;
121 /* delete bar brush */
122 if (infoPtr->ColorBar != CLR_DEFAULT)
123 DeleteObject32 (hbrBar);
125 /* delete background brush */
126 if (infoPtr->ColorBk != CLR_DEFAULT)
127 DeleteObject32 (hbrBk);
131 EndPaint32(wndPtr->hwndSelf, &ps);
134 /***********************************************************************
136 * Makes sure the current position (CUrVal) is within bounds.
138 static void PROGRESS_CoercePos(WND *wndPtr)
140 PROGRESS_INFO *infoPtr = PROGRESS_GetInfoPtr(wndPtr);
142 if(infoPtr->CurVal < infoPtr->MinVal)
143 infoPtr->CurVal = infoPtr->MinVal;
144 if(infoPtr->CurVal > infoPtr->MaxVal)
145 infoPtr->CurVal = infoPtr->MaxVal;
148 /***********************************************************************
151 LRESULT WINAPI ProgressWindowProc(HWND32 hwnd, UINT32 message,
152 WPARAM32 wParam, LPARAM lParam)
154 WND *wndPtr = WIN_FindWndPtr(hwnd);
155 PROGRESS_INFO *infoPtr = PROGRESS_GetInfoPtr(wndPtr);
161 /* allocate memory for info struct */
162 wndPtr->wExtra[0] = HeapAlloc (SystemHeap, HEAP_ZERO_MEMORY,
163 sizeof(PROGRESS_INFO));
164 infoPtr = (PROGRESS_INFO *)wndPtr->wExtra[0];
165 /* initialize the info struct */
170 infoPtr->ColorBar=CLR_DEFAULT;
171 infoPtr->ColorBk=CLR_DEFAULT;
172 TRACE(updown, "Progress Ctrl creation, hwnd=%04x\n", hwnd);
176 TRACE(updown, "Progress Ctrl destruction, hwnd=%04x\n", hwnd);
177 HeapFree (SystemHeap, 0, infoPtr);
181 /* pretend to erase it here, but we will do it in the paint
182 function to avoid flicker */
186 /* FIXME: What do we need to do? */
190 /* FIXME: What do we need to do? */
194 PROGRESS_Paint(wndPtr, wParam);
199 UNKNOWN_PARAM(PBM_DELTAPOS, wParam, lParam);
200 temp = infoPtr->CurVal;
202 infoPtr->CurVal += (UINT16)wParam;
203 PROGRESS_CoercePos(wndPtr);
204 InvalidateRect32 (hwnd, NULL, FALSE);
205 UpdateWindow32 (hwnd);
211 UNKNOWN_PARAM(PBM_SETPOS, wParam, lParam);
212 temp = infoPtr->CurVal;
214 infoPtr->CurVal = (UINT16)wParam;
215 PROGRESS_CoercePos(wndPtr);
216 InvalidateRect32 (hwnd, NULL, FALSE);
217 UpdateWindow32 (hwnd);
223 UNKNOWN_PARAM(PBM_SETRANGE, wParam, lParam);
224 temp = MAKELONG(infoPtr->MinVal, infoPtr->MaxVal);
226 infoPtr->MinVal = LOWORD(lParam);
227 infoPtr->MaxVal = HIWORD(lParam);
228 if(infoPtr->MaxVal <= infoPtr->MinVal)
229 infoPtr->MaxVal = infoPtr->MinVal+1;
230 PROGRESS_CoercePos(wndPtr);
231 InvalidateRect32 (hwnd, NULL, FALSE);
232 UpdateWindow32 (hwnd);
238 UNKNOWN_PARAM(PBM_SETSTEP, wParam, lParam);
239 temp = infoPtr->Step;
240 infoPtr->Step = (UINT16)wParam;
244 if (wParam || lParam)
245 UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);
246 temp = infoPtr->CurVal;
247 infoPtr->CurVal += infoPtr->Step;
248 if(infoPtr->CurVal > infoPtr->MaxVal)
249 infoPtr->CurVal = infoPtr->MinVal;
250 if(temp != infoPtr->CurVal)
252 InvalidateRect32 (hwnd, NULL, FALSE);
253 UpdateWindow32 (hwnd);
258 temp = MAKELONG(infoPtr->MinVal, infoPtr->MaxVal);
259 if((infoPtr->MinVal != (INT32)wParam) ||
260 (infoPtr->MaxVal != (INT32)lParam)) {
261 infoPtr->MinVal = (INT32)wParam;
262 infoPtr->MaxVal = (INT32)lParam;
263 if(infoPtr->MaxVal <= infoPtr->MinVal)
264 infoPtr->MaxVal = infoPtr->MinVal+1;
265 PROGRESS_CoercePos(wndPtr);
266 InvalidateRect32 (hwnd, NULL, FALSE);
267 UpdateWindow32 (hwnd);
273 ((PPBRANGE)lParam)->iLow = infoPtr->MinVal;
274 ((PPBRANGE)lParam)->iHigh = infoPtr->MaxVal;
276 return (wParam) ? infoPtr->MinVal : infoPtr->MaxVal;
279 if (wParam || lParam)
280 UNKNOWN_PARAM(PBM_STEPIT, wParam, lParam);
281 return (infoPtr->CurVal);
283 case PBM_SETBARCOLOR:
285 UNKNOWN_PARAM(PBM_SETBARCOLOR, wParam, lParam);
286 infoPtr->ColorBar = (COLORREF)lParam;
287 InvalidateRect32 (hwnd, NULL, FALSE);
288 UpdateWindow32 (hwnd);
293 UNKNOWN_PARAM(PBM_SETBKCOLOR, wParam, lParam);
294 infoPtr->ColorBk = (COLORREF)lParam;
295 InvalidateRect32 (hwnd, NULL, FALSE);
296 UpdateWindow32 (hwnd);
300 if (message >= WM_USER)
301 ERR(progress, "unknown msg %04x wp=%04x lp=%08lx\n",
302 message, wParam, lParam );
303 return DefWindowProc32A( hwnd, message, wParam, lParam );
310 /***********************************************************************
311 * PROGRESS_Register [Internal]
313 * Registers the progress bar window class.
316 void PROGRESS_Register(void)
318 WNDCLASS32A wndClass;
320 if( GlobalFindAtom32A( PROGRESS_CLASS32A ) ) return;
322 ZeroMemory( &wndClass, sizeof( WNDCLASS32A ) );
323 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
324 wndClass.lpfnWndProc = (WNDPROC32)ProgressWindowProc;
325 wndClass.cbClsExtra = 0;
326 wndClass.cbWndExtra = sizeof(PROGRESS_INFO *);
327 wndClass.hCursor = LoadCursor32A( 0, IDC_ARROW32A );
328 wndClass.lpszClassName = PROGRESS_CLASS32A;
330 RegisterClass32A( &wndClass );