Release 980822
[wine/multimedia.git] / controls / trackbar.c
blob48e587ba43745cfa029aa7a3bcb64cd66f05961d
1 /*
2 * Trackbar control
4 * Copyright 1998 Eric Kohl
6 * NOTES
7 * This is just a dummy control. An author is needed! Any volunteers?
8 * I will only improve this control once in a while.
9 * Eric <ekohl@abo.rhein-zeitung.de>
11 * TODO:
12 * - All messages.
13 * - All notifications.
16 #include "windows.h"
17 #include "commctrl.h"
18 #include "trackbar.h"
19 #include "heap.h"
20 #include "win.h"
21 #include "debug.h"
24 #define TRACKBAR_GetInfoPtr(wndPtr) ((TRACKBAR_INFO *)wndPtr->wExtra[0])
27 static VOID
28 TRACKBAR_Refresh (WND *wndPtr, HDC32 hdc)
30 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
31 RECT32 rect;
33 GetClientRect32 (wndPtr->hwndSelf, &rect);
35 /* draw channel */
36 DrawEdge32 (hdc, &infoPtr->rcChannel, EDGE_SUNKEN, BF_RECT);
38 /* draw thumb */
39 if (!(wndPtr->dwStyle & TBS_NOTHUMB)) {
43 /* draw ticks */
44 if (!(wndPtr->dwStyle & TBS_NOTICKS)) {
48 if (infoPtr->bFocus)
49 DrawFocusRect32 (hdc, &rect);
53 static LRESULT
54 TRACKBAR_ClearSel (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
56 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
58 infoPtr->nSelMin = 0;
59 infoPtr->nSelMax = 0;
61 if ((BOOL32)wParam) {
62 HDC32 hdc = GetDC32 (wndPtr->hwndSelf);
63 TRACKBAR_Refresh (wndPtr, hdc);
64 ReleaseDC32 (wndPtr->hwndSelf, hdc);
67 return 0;
71 // << TRACKBAR_ClearTics >>
72 // << TRACKBAR_GetChannelRect >>
75 static LRESULT
76 TRACKBAR_GetLineSize (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
78 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
80 return infoPtr->nLineSize;
84 // << TRACKBAR_GetNumTics >>
87 static LRESULT
88 TRACKBAR_GetPageSize (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
90 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
92 return infoPtr->nPageSize;
96 static LRESULT
97 TRACKBAR_GetPos (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
99 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
101 return infoPtr->nPos;
105 // << TRACKBAR_GetPTics >>
108 static LRESULT
109 TRACKBAR_GetRangeMax (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
111 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
113 return infoPtr->nRangeMax;
117 static LRESULT
118 TRACKBAR_GetRangeMin (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
120 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
122 return infoPtr->nRangeMin;
126 static LRESULT
127 TRACKBAR_GetSelEnd (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
129 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
131 return infoPtr->nSelMax;
135 static LRESULT
136 TRACKBAR_GetSelStart (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
138 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
140 return infoPtr->nSelMin;
144 static LRESULT
145 TRACKBAR_GetThumbLength (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
147 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
149 return infoPtr->nThumbLen;
157 static LRESULT
158 TRACKBAR_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
160 TRACKBAR_INFO *infoPtr;
162 infoPtr = (TRACKBAR_INFO *)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
163 sizeof(TRACKBAR_INFO));
164 wndPtr->wExtra[0] = (DWORD)infoPtr;
167 /* default values */
168 infoPtr->nRangeMin = 0;
169 infoPtr->nRangeMax = 100;
170 infoPtr->nLineSize = 1;
171 infoPtr->nPageSize = 20;
172 infoPtr->nSelMin = 0;
173 infoPtr->nSelMax = 0;
174 infoPtr->nPos = 0;
175 infoPtr->nThumbLen = 23; /* initial thumb length */
178 return 0;
182 static LRESULT
183 TRACKBAR_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
185 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
190 HeapFree (GetProcessHeap (), 0, infoPtr);
192 return 0;
196 static LRESULT
197 TRACKBAR_KillFocus (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
199 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
200 HDC32 hdc;
202 infoPtr->bFocus = FALSE;
204 hdc = GetDC32 (wndPtr->hwndSelf);
205 TRACKBAR_Refresh (wndPtr, hdc);
206 ReleaseDC32 (wndPtr->hwndSelf, hdc);
208 return 0;
212 static LRESULT
213 TRACKBAR_LButtonDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
215 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
217 SetFocus32 (wndPtr->hwndSelf);
219 return 0;
223 static LRESULT
224 TRACKBAR_Paint (WND *wndPtr, WPARAM32 wParam)
226 HDC32 hdc;
227 PAINTSTRUCT32 ps;
229 hdc = wParam==0 ? BeginPaint32 (wndPtr->hwndSelf, &ps) : (HDC32)wParam;
230 TRACKBAR_Refresh (wndPtr, hdc);
231 if(!wParam)
232 EndPaint32 (wndPtr->hwndSelf, &ps);
233 return 0;
237 static LRESULT
238 TRACKBAR_SetFocus (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
240 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
241 HDC32 hdc;
243 infoPtr->bFocus = TRUE;
245 hdc = GetDC32 (wndPtr->hwndSelf);
246 TRACKBAR_Refresh (wndPtr, hdc);
247 ReleaseDC32 (wndPtr->hwndSelf, hdc);
249 return 0;
253 static LRESULT
254 TRACKBAR_Size (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
256 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(wndPtr);
257 RECT32 rect;
259 GetClientRect32 (wndPtr->hwndSelf, &rect);
261 /* calculate channel rect */
262 if (wndPtr->dwStyle & TBS_VERT) {
263 infoPtr->rcChannel.top = rect.top + 8;
264 infoPtr->rcChannel.bottom = rect.bottom - 8;
266 /* FIXME */
267 infoPtr->rcChannel.left = rect.left + 10;
268 infoPtr->rcChannel.right = rect.left + 14;
271 else {
272 infoPtr->rcChannel.left = rect.left + 8;
273 infoPtr->rcChannel.right = rect.right - 8;
275 /* FIXME */
276 if (wndPtr->dwStyle & TBS_BOTH) {
277 infoPtr->rcChannel.top = rect.bottom / 2 - 2;
278 infoPtr->rcChannel.bottom = rect.bottom / 2 + 2;
281 else if (wndPtr->dwStyle & TBS_TOP) {
282 infoPtr->rcChannel.top = rect.top + 10;
283 infoPtr->rcChannel.bottom = rect.top + 14;
286 else {
287 /* TBS_BOTTOM */
288 infoPtr->rcChannel.top = rect.bottom - 14;
289 infoPtr->rcChannel.bottom = rect.bottom - 10;
293 return 0;
297 // << TRACKBAR_Timer >>
298 // << TRACKBAR_WinIniChange >>
301 LRESULT WINAPI
302 TrackbarWindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
304 WND *wndPtr = WIN_FindWndPtr(hwnd);
306 switch (uMsg)
308 case TBM_CLEARSEL:
309 return TRACKBAR_ClearSel (wndPtr, wParam, lParam);
311 // case TBM_CLEARTICS:
312 // case TBM_GETBUDDY:
313 // case TBM_GETCHANNELRECT:
315 case TBM_GETLINESIZE:
316 return TRACKBAR_GetLineSize (wndPtr, wParam, lParam);
318 // case TBM_GETNUMTICS:
320 case TBM_GETPAGESIZE:
321 return TRACKBAR_GetPageSize (wndPtr, wParam, lParam);
323 case TBM_GETPOS:
324 return TRACKBAR_GetPos (wndPtr, wParam, lParam);
326 // case TBM_GETPTICS:
328 case TBM_GETRANGEMAX:
329 return TRACKBAR_GetRangeMax (wndPtr, wParam, lParam);
331 case TBM_GETRANGEMIN:
332 return TRACKBAR_GetRangeMin (wndPtr, wParam, lParam);
334 case TBM_GETSELEND:
335 return TRACKBAR_GetSelEnd (wndPtr, wParam, lParam);
337 case TBM_GETSELSTART:
338 return TRACKBAR_GetSelStart (wndPtr, wParam, lParam);
340 case TBM_GETTHUMBLENGTH:
341 return TRACKBAR_GetThumbLength (wndPtr, wParam, lParam);
343 // case TBM_GETTHUMBRECT:
344 // case TBM_GETTIC:
345 // case TBM_GETTICPOS:
346 // case TBM_GETTOOLTIPS:
347 // case TBM_GETUNICODEFORMAT:
348 // case TBM_SETBUDDY:
349 // case TBM_SETPAGESIZE:
350 // case TBM_SETPOS:
351 // case TBM_SETRANGE:
352 // case TBM_SETRANGEMAX:
353 // case TBM_SETRANGEMIN:
354 // case TBM_SETSEL:
355 // case TBM_SETSELEND:
356 // case TBM_SETSELSTART:
357 // case TBM_SETTHUMBLENGTH:
358 // case TBM_SETTIC:
359 // case TBM_SETTICFREQ:
360 // case TBM_SETTIPSIDE:
361 // case TBM_SETTOOLTIPS:
362 // case TBM_SETUNICODEFORMAT:
365 // case WM_CAPTURECHANGED:
367 case WM_CREATE:
368 return TRACKBAR_Create (wndPtr, wParam, lParam);
370 case WM_DESTROY:
371 return TRACKBAR_Destroy (wndPtr, wParam, lParam);
373 // case WM_ENABLE:
375 // case WM_ERASEBKGND:
376 // return 0;
378 case WM_GETDLGCODE:
379 return DLGC_WANTARROWS;
381 // case WM_KEYDOWN:
383 // case WM_KEYUP:
385 case WM_KILLFOCUS:
386 return TRACKBAR_KillFocus (wndPtr, wParam, lParam);
388 case WM_LBUTTONDOWN:
389 return TRACKBAR_LButtonDown (wndPtr, wParam, lParam);
391 // case WM_LBUTTONUP:
393 // case WM_MOUSEMOVE:
394 // return TRACKBAR_MouseMove (wndPtr, wParam, lParam);
396 case WM_PAINT:
397 return TRACKBAR_Paint (wndPtr, wParam);
399 case WM_SETFOCUS:
400 return TRACKBAR_SetFocus (wndPtr, wParam, lParam);
402 case WM_SIZE:
403 return TRACKBAR_Size (wndPtr, wParam, lParam);
405 // case WM_TIMER:
407 // case WM_WININICHANGE:
409 default:
410 if (uMsg >= WM_USER)
411 ERR (trackbar, "unknown msg %04x wp=%08x lp=%08lx\n",
412 uMsg, wParam, lParam);
413 return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
415 return 0;
419 void
420 TRACKBAR_Register (void)
422 WNDCLASS32A wndClass;
424 if (GlobalFindAtom32A (TRACKBAR_CLASS32A)) return;
426 ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
427 wndClass.style = CS_GLOBALCLASS;
428 wndClass.lpfnWndProc = (WNDPROC32)TrackbarWindowProc;
429 wndClass.cbClsExtra = 0;
430 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
431 wndClass.hCursor = LoadCursor32A (0, IDC_ARROW32A);
432 wndClass.hbrBackground = (HBRUSH32)(COLOR_3DFACE + 1);
433 wndClass.lpszClassName = TRACKBAR_CLASS32A;
435 RegisterClass32A (&wndClass);