dplayx: Code to forward player creation
[wine/gsoc_dplay.git] / dlls / comctl32 / trackbar.c
blob849ebcd627d4b318b74c1e76d5c9b94099b7f2e5
1 /*
2 * Trackbar control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1998, 1999 Alex Priem
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTE
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "winnls.h"
43 #include "commctrl.h"
44 #include "uxtheme.h"
45 #include "tmschema.h"
46 #include "wine/debug.h"
48 #include "comctl32.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
52 typedef struct
54 HWND hwndSelf;
55 LONG lRangeMin;
56 LONG lRangeMax;
57 LONG lLineSize;
58 LONG lPageSize;
59 LONG lSelMin;
60 LONG lSelMax;
61 LONG lPos;
62 UINT uThumbLen;
63 UINT uNumTics;
64 UINT uTicFreq;
65 HWND hwndNotify;
66 HWND hwndToolTip;
67 HWND hwndBuddyLA;
68 HWND hwndBuddyRB;
69 INT fLocation;
70 INT flags;
71 BOOL bUnicode;
72 BOOL bFocussed;
73 RECT rcChannel;
74 RECT rcSelection;
75 RECT rcThumb;
76 LPLONG tics;
77 } TRACKBAR_INFO;
79 #define TB_REFRESH_TIMER 1
80 #define TB_REFRESH_DELAY 500
82 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
84 #define TB_DEFAULTPAGESIZE 20
86 /* Used by TRACKBAR_Refresh to find out which parts of the control
87 need to be recalculated */
89 #define TB_THUMBPOSCHANGED 1
90 #define TB_THUMBSIZECHANGED 2
91 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
92 #define TB_SELECTIONCHANGED 4
93 #define TB_DRAG_MODE 8 /* we're dragging the slider */
94 #define TB_AUTO_PAGE_LEFT 16
95 #define TB_AUTO_PAGE_RIGHT 32
96 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
97 #define TB_THUMB_HOT 64 /* mouse hovers above thumb */
99 /* helper defines for TRACKBAR_DrawTic */
100 #define TIC_EDGE 0x20
101 #define TIC_SELECTIONMARKMAX 0x80
102 #define TIC_SELECTIONMARKMIN 0x100
103 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
105 static const WCHAR themeClass[] = { 'T','r','a','c','k','b','a','r',0 };
107 static inline int
108 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
110 pnmcd->dwDrawStage = stage;
111 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
112 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
115 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
117 LRESULT result;
119 TRACE("(code=%d)\n", code);
121 pnmh->hwndFrom = infoPtr->hwndSelf;
122 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
123 pnmh->code = code;
124 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
126 TRACE(" <= %ld\n", result);
128 return result;
131 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
133 NMHDR nmh;
134 return notify_hdr(infoPtr, code, &nmh);
137 static BOOL
138 notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
140 BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT;
142 TRACE("%x\n", code);
144 return (BOOL) SendMessageW (infoPtr->hwndNotify,
145 bVert ? WM_VSCROLL : WM_HSCROLL,
146 (WPARAM)code, (LPARAM)infoPtr->hwndSelf);
149 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
151 int tic;
152 unsigned nrTics, i;
154 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin)
155 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
156 else {
157 Free (infoPtr->tics);
158 infoPtr->tics = NULL;
159 infoPtr->uNumTics = 0;
160 return;
163 if (nrTics != infoPtr->uNumTics) {
164 infoPtr->tics=ReAlloc (infoPtr->tics,
165 (nrTics+1)*sizeof (DWORD));
166 if (!infoPtr->tics) {
167 infoPtr->uNumTics = 0;
168 notify(infoPtr, NM_OUTOFMEMORY);
169 return;
171 infoPtr->uNumTics = nrTics;
174 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
175 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
176 infoPtr->tics[i] = tic;
179 /* converts from physical (mouse) position to logical position
180 (in range of trackbar) */
182 static inline LONG
183 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place, int vertical)
185 double range, width, pos, offsetthumb;
187 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
188 if (vertical) {
189 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
190 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
191 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
192 } else {
193 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
194 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
195 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
197 pos += infoPtr->lRangeMin;
198 if (pos > infoPtr->lRangeMax)
199 pos = infoPtr->lRangeMax;
200 else if (pos < infoPtr->lRangeMin)
201 pos = infoPtr->lRangeMin;
203 TRACE("%.2f\n", pos);
204 return (LONG)(pos + 0.5);
208 /* return: 0> prev, 0 none, >0 next */
209 static LONG
210 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
212 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
213 RECT pageRect;
215 if (dwStyle & TBS_VERT) {
216 pageRect.top = infoPtr->rcChannel.top;
217 pageRect.bottom = infoPtr->rcChannel.bottom;
218 pageRect.left = infoPtr->rcThumb.left;
219 pageRect.right = infoPtr->rcThumb.right;
220 } else {
221 pageRect.top = infoPtr->rcThumb.top;
222 pageRect.bottom = infoPtr->rcThumb.bottom;
223 pageRect.left = infoPtr->rcChannel.left;
224 pageRect.right = infoPtr->rcChannel.right;
228 if (PtInRect(&pageRect, clickPoint))
230 int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
232 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace,
233 dwStyle & TBS_VERT);
234 return clickPos - infoPtr->lPos;
237 return 0;
240 static inline void
241 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
243 if (infoPtr->lPos == infoPtr->lRangeMax) return;
245 infoPtr->lPos += infoPtr->lPageSize;
246 if (infoPtr->lPos > infoPtr->lRangeMax)
247 infoPtr->lPos = infoPtr->lRangeMax;
248 notify_with_scroll (infoPtr, TB_PAGEDOWN);
252 static inline void
253 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
255 if (infoPtr->lPos == infoPtr->lRangeMin) return;
257 infoPtr->lPos -= infoPtr->lPageSize;
258 if (infoPtr->lPos < infoPtr->lRangeMin)
259 infoPtr->lPos = infoPtr->lRangeMin;
260 notify_with_scroll (infoPtr, TB_PAGEUP);
263 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
265 if (infoPtr->lPos == infoPtr->lRangeMin) return;
266 infoPtr->lPos -= infoPtr->lLineSize;
267 if (infoPtr->lPos < infoPtr->lRangeMin)
268 infoPtr->lPos = infoPtr->lRangeMin;
269 notify_with_scroll (infoPtr, TB_LINEUP);
272 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
274 if (infoPtr->lPos == infoPtr->lRangeMax) return;
275 infoPtr->lPos += infoPtr->lLineSize;
276 if (infoPtr->lPos > infoPtr->lRangeMax)
277 infoPtr->lPos = infoPtr->lRangeMax;
278 notify_with_scroll (infoPtr, TB_LINEDOWN);
281 static void
282 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
284 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
285 INT cyChannel, offsetthumb, offsetedge;
286 RECT lpRect, *channel = & infoPtr->rcChannel;
288 GetClientRect (infoPtr->hwndSelf, &lpRect);
290 offsetthumb = infoPtr->uThumbLen / 4;
291 offsetedge = offsetthumb + 3;
292 cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
293 if (dwStyle & TBS_VERT) {
294 channel->top = lpRect.top + offsetedge;
295 channel->bottom = lpRect.bottom - offsetedge;
296 if (dwStyle & TBS_ENABLESELRANGE)
297 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
298 else
299 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
300 if (dwStyle & TBS_BOTH) {
301 if (dwStyle & TBS_NOTICKS)
302 channel->left += 1;
303 else
304 channel->left += 9;
306 else if (dwStyle & TBS_TOP) {
307 if (dwStyle & TBS_NOTICKS)
308 channel->left += 2;
309 else
310 channel->left += 10;
312 channel->right = channel->left + cyChannel;
313 } else {
314 channel->left = lpRect.left + offsetedge;
315 channel->right = lpRect.right - offsetedge;
316 if (dwStyle & TBS_ENABLESELRANGE)
317 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
318 else
319 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
320 if (dwStyle & TBS_BOTH) {
321 if (dwStyle & TBS_NOTICKS)
322 channel->top += 1;
323 else
324 channel->top += 9;
326 else if (dwStyle & TBS_TOP) {
327 if (dwStyle & TBS_NOTICKS)
328 channel->top += 2;
329 else
330 channel->top += 10;
332 channel->bottom = channel->top + cyChannel;
336 static void
337 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
339 int range, width, height, thumbwidth;
340 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
341 RECT lpRect;
343 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
344 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
346 if (!range) range = 1;
348 GetClientRect(infoPtr->hwndSelf, &lpRect);
349 if (dwStyle & TBS_VERT)
351 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
353 if ((dwStyle & (TBS_BOTH | TBS_LEFT)) && !(dwStyle & TBS_NOTICKS))
354 thumb->left = 10;
355 else
356 thumb->left = 2;
357 thumb->right = thumb->left + infoPtr->uThumbLen;
358 thumb->top = infoPtr->rcChannel.top +
359 (height*(lPos - infoPtr->lRangeMin))/range;
360 thumb->bottom = thumb->top + thumbwidth;
362 else
364 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
366 thumb->left = infoPtr->rcChannel.left +
367 (width*(lPos - infoPtr->lRangeMin))/range;
368 thumb->right = thumb->left + thumbwidth;
369 if ((dwStyle & (TBS_BOTH | TBS_TOP)) && !(dwStyle & TBS_NOTICKS))
370 thumb->top = 10;
371 else
372 thumb->top = 2;
373 thumb->bottom = thumb->top + infoPtr->uThumbLen;
377 static inline void
378 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
380 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
383 static inline void
384 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
386 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
389 static void
390 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
392 RECT rcThumb;
394 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
395 InflateRect(&rcThumb, 1, 1);
396 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
399 static inline void
400 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
402 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
403 if (newPos != oldPos)
404 TRACKBAR_InvalidateThumb (infoPtr, newPos);
407 static inline BOOL
408 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
410 return infoPtr->lSelMin != infoPtr->lSelMax;
413 static void
414 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
416 RECT *selection = &infoPtr->rcSelection;
417 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
418 int offsetthumb, height, width;
420 if (range <= 0) {
421 SetRectEmpty (selection);
422 } else {
423 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) {
424 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
425 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
426 selection->top = infoPtr->rcChannel.top + offsetthumb +
427 (height*infoPtr->lSelMin)/range;
428 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
429 (height*infoPtr->lSelMax)/range;
430 selection->left = infoPtr->rcChannel.left + 3;
431 selection->right = infoPtr->rcChannel.right - 3;
432 } else {
433 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
434 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
435 selection->left = infoPtr->rcChannel.left + offsetthumb +
436 (width*infoPtr->lSelMin)/range;
437 selection->right = infoPtr->rcChannel.left + offsetthumb +
438 (width*infoPtr->lSelMax)/range;
439 selection->top = infoPtr->rcChannel.top + 3;
440 selection->bottom = infoPtr->rcChannel.bottom - 3;
444 TRACE("selection[%s]\n", wine_dbgstr_rect(selection));
447 static BOOL
448 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
450 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
451 LONG prevPos = infoPtr->lPos;
453 TRACE("x=%d, y=%d, dir=%d\n", clickPoint.x, clickPoint.y, dir);
455 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
456 TRACKBAR_PageDown(infoPtr);
457 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
458 TRACKBAR_PageUp(infoPtr);
459 else return FALSE;
461 infoPtr->flags |= TB_THUMBPOSCHANGED;
462 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
464 return TRUE;
467 /* Trackbar drawing code. I like my spaghetti done milanese. */
469 static void
470 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
472 RECT rcChannel = infoPtr->rcChannel;
473 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
475 if (theme)
477 DrawThemeBackground (theme, hdc,
478 (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) ?
479 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
481 else
483 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
484 if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
485 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
486 if (TRACKBAR_HasSelection(infoPtr))
487 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
492 static void
493 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
495 int x, y, ox, oy, range, side, indent = 0, len = 3;
496 int offsetthumb;
497 RECT rcTics;
499 if (flags & TBS_VERT) {
500 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
501 rcTics.left = infoPtr->rcThumb.left - 2;
502 rcTics.right = infoPtr->rcThumb.right + 2;
503 rcTics.top = infoPtr->rcChannel.top + offsetthumb + 1;
504 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb;
505 } else {
506 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
507 rcTics.left = infoPtr->rcChannel.left + offsetthumb + 1;
508 rcTics.right = infoPtr->rcChannel.right - offsetthumb;
509 rcTics.top = infoPtr->rcThumb.top - 2;
510 rcTics.bottom = infoPtr->rcThumb.bottom + 2;
513 if (flags & (TBS_TOP | TBS_LEFT)) {
514 x = rcTics.left;
515 y = rcTics.top;
516 side = -1;
517 } else {
518 x = rcTics.right;
519 y = rcTics.bottom;
520 side = 1;
523 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
524 if (range <= 0)
525 range = 1; /* to avoid division by zero */
527 if (flags & TIC_SELECTIONMARK) {
528 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
529 } else if (flags & TIC_EDGE) {
530 len++;
533 if (flags & TBS_VERT) {
534 int height = rcTics.bottom - rcTics.top;
535 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
536 } else {
537 int width = rcTics.right - rcTics.left;
538 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
541 ox = x;
542 oy = y;
543 MoveToEx(hdc, x, y, 0);
544 if (flags & TBS_VERT) x += len * side;
545 else y += len * side;
546 LineTo(hdc, x, y);
548 if (flags & TIC_SELECTIONMARK) {
549 if (flags & TBS_VERT) {
550 x -= side;
551 } else {
552 y -= side;
554 MoveToEx(hdc, x, y, 0);
555 if (flags & TBS_VERT) {
556 y += 2 * indent;
557 } else {
558 x += 2 * indent;
561 LineTo(hdc, x, y);
562 LineTo(hdc, ox, oy);
567 static inline void
568 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
570 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
571 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
573 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
574 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
577 static void
578 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
580 unsigned int i;
581 int ticFlags = dwStyle & 0x0f;
582 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
583 HPEN hOldPen, hTicPen;
584 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
586 if (theme)
588 int part = (dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
589 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
591 /* create the pen to draw the tics with */
592 hTicPen = CreatePenIndirect(&ticPen);
593 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
595 /* actually draw the tics */
596 for (i=0; i<infoPtr->uNumTics; i++)
597 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
599 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
600 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
602 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
603 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
604 ticFlags | TIC_SELECTIONMARKMIN);
605 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
606 ticFlags | TIC_SELECTIONMARKMAX);
609 /* clean up the pen, if we created one */
610 if (hTicPen) {
611 SelectObject(hdc, hOldPen);
612 DeleteObject(hTicPen);
616 static void
617 TRACKBAR_DrawThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
619 HBRUSH oldbr;
620 HPEN oldpen;
621 RECT thumb = infoPtr->rcThumb;
622 int BlackUntil = 3;
623 int PointCount = 6;
624 POINT points[6];
625 int fillClr;
626 int PointDepth;
627 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
629 if (theme)
631 int partId;
632 int stateId;
633 if (dwStyle & TBS_BOTH)
634 partId = (dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
635 else if (dwStyle & TBS_LEFT)
636 partId = (dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
637 else
638 partId = (dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
640 if (dwStyle & WS_DISABLED)
641 stateId = TUS_DISABLED;
642 else if (infoPtr->flags & TB_DRAG_MODE)
643 stateId = TUS_PRESSED;
644 else if (infoPtr->flags & TB_THUMB_HOT)
645 stateId = TUS_HOT;
646 else
647 stateId = TUS_NORMAL;
649 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
651 return;
654 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
655 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
656 SetPolyFillMode (hdc, WINDING);
658 if (dwStyle & TBS_BOTH)
660 points[0].x=thumb.right;
661 points[0].y=thumb.top;
662 points[1].x=thumb.right;
663 points[1].y=thumb.bottom;
664 points[2].x=thumb.left;
665 points[2].y=thumb.bottom;
666 points[3].x=thumb.left;
667 points[3].y=thumb.top;
668 points[4].x=points[0].x;
669 points[4].y=points[0].y;
670 PointCount = 5;
671 BlackUntil = 3;
673 else
675 if (dwStyle & TBS_VERT)
677 PointDepth = (thumb.bottom - thumb.top) / 2;
678 if (dwStyle & TBS_LEFT)
680 points[0].x=thumb.right;
681 points[0].y=thumb.top;
682 points[1].x=thumb.right;
683 points[1].y=thumb.bottom;
684 points[2].x=thumb.left + PointDepth;
685 points[2].y=thumb.bottom;
686 points[3].x=thumb.left;
687 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
688 points[4].x=thumb.left + PointDepth;
689 points[4].y=thumb.top;
690 points[5].x=points[0].x;
691 points[5].y=points[0].y;
692 BlackUntil = 4;
694 else
696 points[0].x=thumb.right;
697 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
698 points[1].x=thumb.right - PointDepth;
699 points[1].y=thumb.bottom;
700 points[2].x=thumb.left;
701 points[2].y=thumb.bottom;
702 points[3].x=thumb.left;
703 points[3].y=thumb.top;
704 points[4].x=thumb.right - PointDepth;
705 points[4].y=thumb.top;
706 points[5].x=points[0].x;
707 points[5].y=points[0].y;
710 else
712 PointDepth = (thumb.right - thumb.left) / 2;
713 if (dwStyle & TBS_TOP)
715 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
716 points[0].y=thumb.top;
717 points[1].x=thumb.right;
718 points[1].y=thumb.top + PointDepth;
719 points[2].x=thumb.right;
720 points[2].y=thumb.bottom;
721 points[3].x=thumb.left;
722 points[3].y=thumb.bottom;
723 points[4].x=thumb.left;
724 points[4].y=thumb.top + PointDepth;
725 points[5].x=points[0].x;
726 points[5].y=points[0].y;
727 BlackUntil = 4;
729 else
731 points[0].x=thumb.right;
732 points[0].y=thumb.top;
733 points[1].x=thumb.right;
734 points[1].y=thumb.bottom - PointDepth;
735 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
736 points[2].y=thumb.bottom;
737 points[3].x=thumb.left;
738 points[3].y=thumb.bottom - PointDepth;
739 points[4].x=thumb.left;
740 points[4].y=thumb.top;
741 points[5].x=points[0].x;
742 points[5].y=points[0].y;
748 /* Draw the thumb now */
749 Polygon (hdc, points, PointCount);
750 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
751 Polyline(hdc,points, BlackUntil);
752 SelectObject(hdc, GetStockObject(WHITE_PEN));
753 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
754 SelectObject(hdc, oldpen);
755 SelectObject(hdc, oldbr);
759 static inline void
760 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
762 TTTOOLINFOW ti;
764 if (!infoPtr->hwndToolTip) return;
766 ZeroMemory(&ti, sizeof(ti));
767 ti.cbSize = sizeof(ti);
768 ti.hwnd = infoPtr->hwndSelf;
770 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
774 static void
775 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
777 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
778 WCHAR buf[80];
779 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
780 TTTOOLINFOW ti;
781 POINT pt;
782 RECT rcClient;
783 LRESULT size;
785 if (!infoPtr->hwndToolTip) return;
787 ZeroMemory(&ti, sizeof(ti));
788 ti.cbSize = sizeof(ti);
789 ti.hwnd = infoPtr->hwndSelf;
790 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
792 wsprintfW (buf, fmt, infoPtr->lPos);
793 ti.lpszText = buf;
794 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
796 GetClientRect (infoPtr->hwndSelf, &rcClient);
797 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
798 if (dwStyle & TBS_VERT) {
799 if (infoPtr->fLocation == TBTS_LEFT)
800 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
801 else
802 pt.x = rcClient.right + TOOLTIP_OFFSET;
803 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
804 } else {
805 if (infoPtr->fLocation == TBTS_TOP)
806 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
807 else
808 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
809 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
811 ClientToScreen(infoPtr->hwndSelf, &pt);
813 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
814 0, MAKELPARAM(pt.x, pt.y));
818 static void
819 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
821 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
822 RECT rcClient;
823 HDC hdc;
824 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
825 NMCUSTOMDRAW nmcd;
826 int gcdrf, icdrf;
828 if (infoPtr->flags & TB_THUMBCHANGED) {
829 TRACKBAR_UpdateThumb (infoPtr);
830 if (infoPtr->flags & TB_THUMBSIZECHANGED)
831 TRACKBAR_CalcChannel (infoPtr);
833 if (infoPtr->flags & TB_SELECTIONCHANGED)
834 TRACKBAR_CalcSelection (infoPtr);
836 if (infoPtr->flags & TB_DRAG_MODE)
837 TRACKBAR_UpdateToolTip (infoPtr);
839 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
841 GetClientRect (infoPtr->hwndSelf, &rcClient);
843 /* try to render offscreen, if we fail, carrry onscreen */
844 hdc = CreateCompatibleDC(hdcDst);
845 if (hdc) {
846 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
847 if (hOffScreenBmp) {
848 hOldBmp = SelectObject(hdc, hOffScreenBmp);
849 } else {
850 DeleteObject(hdc);
851 hdc = hdcDst;
853 } else {
854 hdc = hdcDst;
857 ZeroMemory(&nmcd, sizeof(nmcd));
858 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
859 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
860 nmcd.hdr.code = NM_CUSTOMDRAW;
861 nmcd.hdc = hdc;
863 /* start the paint cycle */
864 nmcd.rc = rcClient;
865 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
866 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
868 /* Erase background */
869 if (gcdrf == CDRF_DODEFAULT ||
870 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
871 if (GetWindowTheme (infoPtr->hwndSelf)) {
872 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
874 else
875 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
876 if (gcdrf != CDRF_DODEFAULT)
877 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
880 /* draw channel */
881 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
882 nmcd.dwItemSpec = TBCD_CHANNEL;
883 nmcd.uItemState = CDIS_DEFAULT;
884 nmcd.rc = infoPtr->rcChannel;
885 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
886 } else icdrf = CDRF_DODEFAULT;
887 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
888 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
889 if (icdrf & CDRF_NOTIFYPOSTPAINT)
890 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
894 /* draw tics */
895 if (!(dwStyle & TBS_NOTICKS)) {
896 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
897 nmcd.dwItemSpec = TBCD_TICS;
898 nmcd.uItemState = CDIS_DEFAULT;
899 nmcd.rc = rcClient;
900 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
901 } else icdrf = CDRF_DODEFAULT;
902 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
903 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
904 if (icdrf & CDRF_NOTIFYPOSTPAINT)
905 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
909 /* draw thumb */
910 if (!(dwStyle & TBS_NOTHUMB)) {
911 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
912 nmcd.dwItemSpec = TBCD_THUMB;
913 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
914 nmcd.rc = infoPtr->rcThumb;
915 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
916 } else icdrf = CDRF_DODEFAULT;
917 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
918 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
919 if (icdrf & CDRF_NOTIFYPOSTPAINT)
920 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
924 /* draw focus rectangle */
925 if (infoPtr->bFocussed) {
926 DrawFocusRect(hdc, &rcClient);
929 /* finish up the painting */
930 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
931 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
933 cleanup:
934 /* cleanup, if we rendered offscreen */
935 if (hdc != hdcDst) {
936 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
937 SelectObject(hdc, hOldBmp);
938 DeleteObject(hOffScreenBmp);
939 DeleteObject(hdc);
944 static void
945 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
947 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
948 HWND hwndParent = GetParent (infoPtr->hwndSelf);
949 RECT rcSelf, rcBuddy;
950 INT x, y;
952 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
953 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
955 /* align buddy left or above */
956 if (infoPtr->hwndBuddyLA) {
957 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
958 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
960 if (dwStyle & TBS_VERT) {
961 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
962 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
963 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
965 else {
966 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
967 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
968 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
971 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
972 SWP_NOZORDER | SWP_NOSIZE);
976 /* align buddy right or below */
977 if (infoPtr->hwndBuddyRB) {
978 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
979 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
981 if (dwStyle & TBS_VERT) {
982 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
983 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
984 y = rcSelf.bottom;
986 else {
987 x = rcSelf.right;
988 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
989 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
991 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
992 SWP_NOZORDER | SWP_NOSIZE);
997 static LRESULT
998 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1000 infoPtr->lSelMin = 0;
1001 infoPtr->lSelMax = 0;
1002 infoPtr->flags |= TB_SELECTIONCHANGED;
1004 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1006 return 0;
1010 static LRESULT
1011 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1013 if (infoPtr->tics) {
1014 Free (infoPtr->tics);
1015 infoPtr->tics = NULL;
1016 infoPtr->uNumTics = 0;
1019 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1021 return 0;
1025 static inline LRESULT
1026 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1028 if (lprc == NULL) return 0;
1030 lprc->left = infoPtr->rcChannel.left;
1031 lprc->right = infoPtr->rcChannel.right;
1032 lprc->bottom = infoPtr->rcChannel.bottom;
1033 lprc->top = infoPtr->rcChannel.top;
1035 return 0;
1039 static inline LONG
1040 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1042 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
1043 return 0;
1045 if(infoPtr->uNumTics == 0)
1046 return 2;
1047 else
1048 return infoPtr->uNumTics + 1;
1052 static int comp_tics (const void *ap, const void *bp)
1054 const DWORD a = *(const DWORD *)ap;
1055 const DWORD b = *(const DWORD *)bp;
1057 TRACE("(a=%d, b=%d)\n", a, b);
1058 if (a < b) return -1;
1059 if (a > b) return 1;
1060 return 0;
1064 static inline LONG
1065 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1067 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1068 return -1;
1070 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1071 return infoPtr->tics[iTic];
1075 static inline LONG
1076 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1078 LONG range, width, pos, tic;
1079 int offsetthumb;
1081 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1082 return -1;
1084 tic = TRACKBAR_GetTic (infoPtr, iTic);
1085 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1086 if (range <= 0) range = 1;
1087 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1088 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1089 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1091 return pos;
1095 static HWND
1096 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1098 HWND hwndTemp;
1100 if (fLocation) {
1101 /* buddy is left or above */
1102 hwndTemp = infoPtr->hwndBuddyLA;
1103 infoPtr->hwndBuddyLA = hwndBuddy;
1105 else {
1106 /* buddy is right or below */
1107 hwndTemp = infoPtr->hwndBuddyRB;
1108 infoPtr->hwndBuddyRB = hwndBuddy;
1111 TRACKBAR_AlignBuddies (infoPtr);
1113 return hwndTemp;
1117 static inline LONG
1118 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1120 LONG lTemp = infoPtr->lLineSize;
1122 infoPtr->lLineSize = lLineSize;
1124 return lTemp;
1128 static inline LONG
1129 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1131 LONG lTemp = infoPtr->lPageSize;
1133 if (lPageSize != -1)
1134 infoPtr->lPageSize = lPageSize;
1135 else
1136 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1138 return lTemp;
1142 static inline LRESULT
1143 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1145 LONG oldPos = infoPtr->lPos;
1146 infoPtr->lPos = lPosition;
1148 if (infoPtr->lPos < infoPtr->lRangeMin)
1149 infoPtr->lPos = infoPtr->lRangeMin;
1151 if (infoPtr->lPos > infoPtr->lRangeMax)
1152 infoPtr->lPos = infoPtr->lRangeMax;
1153 infoPtr->flags |= TB_THUMBPOSCHANGED;
1155 if (fPosition && oldPos != lPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1157 return 0;
1161 static inline LRESULT
1162 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1164 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1165 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1167 if (infoPtr->lPos < infoPtr->lRangeMin) {
1168 infoPtr->lPos = infoPtr->lRangeMin;
1169 infoPtr->flags |= TB_THUMBPOSCHANGED;
1172 if (infoPtr->lPos > infoPtr->lRangeMax) {
1173 infoPtr->lPos = infoPtr->lRangeMax;
1174 infoPtr->flags |= TB_THUMBPOSCHANGED;
1177 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1178 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1180 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1182 return 0;
1186 static inline LRESULT
1187 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1189 infoPtr->lRangeMax = lMax;
1190 if (infoPtr->lPos > infoPtr->lRangeMax) {
1191 infoPtr->lPos = infoPtr->lRangeMax;
1192 infoPtr->flags |= TB_THUMBPOSCHANGED;
1195 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1196 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1198 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1200 return 0;
1204 static inline LRESULT
1205 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1207 infoPtr->lRangeMin = lMin;
1208 if (infoPtr->lPos < infoPtr->lRangeMin) {
1209 infoPtr->lPos = infoPtr->lRangeMin;
1210 infoPtr->flags |= TB_THUMBPOSCHANGED;
1213 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1214 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1216 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1218 return 0;
1222 static inline LRESULT
1223 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1225 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1226 infoPtr->lSelMin = 0;
1227 infoPtr->lSelMax = 0;
1228 return 0;
1231 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1232 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1233 infoPtr->flags |= TB_SELECTIONCHANGED;
1235 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1236 infoPtr->lSelMin = infoPtr->lRangeMin;
1237 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1238 infoPtr->lSelMax = infoPtr->lRangeMax;
1240 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1242 return 0;
1246 static inline LRESULT
1247 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1249 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1250 infoPtr->lSelMax = 0;
1251 return 0;
1254 infoPtr->lSelMax = lEnd;
1255 infoPtr->flags |= TB_SELECTIONCHANGED;
1257 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1258 infoPtr->lSelMax = infoPtr->lRangeMax;
1260 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1262 return 0;
1266 static inline LRESULT
1267 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1269 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1270 infoPtr->lSelMin = 0;
1271 return 0;
1274 infoPtr->lSelMin = lStart;
1275 infoPtr->flags |=TB_SELECTIONCHANGED;
1277 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1278 infoPtr->lSelMin = infoPtr->lRangeMin;
1280 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1282 return 0;
1286 static inline LRESULT
1287 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1289 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) {
1290 infoPtr->uThumbLen = iLength;
1291 infoPtr->flags |= TB_THUMBSIZECHANGED;
1292 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1295 return 0;
1299 static inline LRESULT
1300 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1302 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1303 return FALSE;
1305 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1306 return FALSE;
1308 TRACE("lPos=%d\n", lPos);
1310 infoPtr->uNumTics++;
1311 infoPtr->tics=ReAlloc( infoPtr->tics,
1312 (infoPtr->uNumTics)*sizeof (DWORD));
1313 if (!infoPtr->tics) {
1314 infoPtr->uNumTics = 0;
1315 notify(infoPtr, NM_OUTOFMEMORY);
1316 return FALSE;
1318 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1320 TRACKBAR_InvalidateAll(infoPtr);
1322 return TRUE;
1326 static inline LRESULT
1327 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1329 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1330 infoPtr->uTicFreq = wFreq;
1331 TRACKBAR_RecalculateTics (infoPtr);
1332 TRACKBAR_InvalidateAll(infoPtr);
1335 return 0;
1339 static inline INT
1340 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1342 INT fTemp = infoPtr->fLocation;
1344 infoPtr->fLocation = fLocation;
1346 return fTemp;
1350 static inline LRESULT
1351 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1353 infoPtr->hwndToolTip = hwndTT;
1355 return 0;
1359 static inline BOOL
1360 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1362 BOOL bTemp = infoPtr->bUnicode;
1364 infoPtr->bUnicode = fUnicode;
1366 return bTemp;
1370 static LRESULT
1371 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1373 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1374 RECT rect;
1375 int clientWidth, clientMetric;
1377 /* initial thumb length */
1378 clientMetric = (dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1379 GetClientRect(infoPtr->hwndSelf,&rect);
1380 if (dwStyle & TBS_VERT) {
1381 clientWidth = rect.right - rect.left;
1382 } else {
1383 clientWidth = rect.bottom - rect.top;
1385 if (clientWidth >= clientMetric)
1386 infoPtr->uThumbLen = clientMetric;
1387 else
1388 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1390 TRACKBAR_CalcChannel (infoPtr);
1391 TRACKBAR_UpdateThumb (infoPtr);
1392 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1394 return 0;
1398 static LRESULT
1399 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1401 TRACKBAR_INFO *infoPtr;
1402 DWORD dwStyle;
1404 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1405 if (!infoPtr) return -1;
1406 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1408 /* set default values */
1409 infoPtr->hwndSelf = hwnd;
1410 infoPtr->lRangeMin = 0;
1411 infoPtr->lRangeMax = 100;
1412 infoPtr->lLineSize = 1;
1413 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1414 infoPtr->lSelMin = 0;
1415 infoPtr->lSelMax = 0;
1416 infoPtr->lPos = 0;
1417 infoPtr->fLocation = -1;
1418 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1419 infoPtr->uTicFreq = 1;
1420 infoPtr->tics = NULL;
1421 infoPtr->hwndNotify= lpcs->hwndParent;
1423 TRACKBAR_InitializeThumb (infoPtr);
1425 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1427 /* Create tooltip control */
1428 if (dwStyle & TBS_TOOLTIPS) {
1430 infoPtr->hwndToolTip =
1431 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1432 CW_USEDEFAULT, CW_USEDEFAULT,
1433 CW_USEDEFAULT, CW_USEDEFAULT,
1434 hwnd, 0, 0, 0);
1436 if (infoPtr->hwndToolTip) {
1437 TTTOOLINFOW ti;
1438 ZeroMemory (&ti, sizeof(ti));
1439 ti.cbSize = sizeof(ti);
1440 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1441 ti.hwnd = hwnd;
1443 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1447 OpenThemeData (hwnd, themeClass);
1449 return 0;
1453 static LRESULT
1454 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1456 /* delete tooltip control */
1457 if (infoPtr->hwndToolTip)
1458 DestroyWindow (infoPtr->hwndToolTip);
1460 Free (infoPtr->tics);
1461 infoPtr->tics = NULL;
1463 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1464 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1465 Free (infoPtr);
1467 return 0;
1471 static LRESULT
1472 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1474 TRACE("\n");
1475 infoPtr->bFocussed = FALSE;
1476 TRACKBAR_InvalidateAll(infoPtr);
1478 return 0;
1481 static LRESULT
1482 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1484 POINT clickPoint;
1486 clickPoint.x = x;
1487 clickPoint.y = y;
1489 SetFocus(infoPtr->hwndSelf);
1491 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1492 infoPtr->flags |= TB_DRAG_MODE;
1493 SetCapture (infoPtr->hwndSelf);
1494 TRACKBAR_UpdateToolTip (infoPtr);
1495 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1496 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1497 } else {
1498 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1499 if (dir == 0) return 0;
1500 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1501 TRACKBAR_AutoPage (infoPtr, clickPoint);
1502 SetCapture (infoPtr->hwndSelf);
1503 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1506 return 0;
1510 static LRESULT
1511 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1513 if (infoPtr->flags & TB_DRAG_MODE) {
1514 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1515 notify_with_scroll (infoPtr, TB_ENDTRACK);
1516 infoPtr->flags &= ~TB_DRAG_MODE;
1517 ReleaseCapture ();
1518 notify(infoPtr, NM_RELEASEDCAPTURE);
1519 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1520 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1522 if (infoPtr->flags & TB_AUTO_PAGE) {
1523 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1524 infoPtr->flags &= ~TB_AUTO_PAGE;
1525 notify_with_scroll (infoPtr, TB_ENDTRACK);
1526 ReleaseCapture ();
1527 notify(infoPtr, NM_RELEASEDCAPTURE);
1530 return 0;
1534 static LRESULT
1535 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1537 notify_with_scroll (infoPtr, TB_ENDTRACK);
1538 return 0;
1542 static LRESULT
1543 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1545 if (hdc) {
1546 TRACKBAR_Refresh(infoPtr, hdc);
1547 } else {
1548 PAINTSTRUCT ps;
1549 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1550 TRACKBAR_Refresh (infoPtr, hdc);
1551 EndPaint (infoPtr->hwndSelf, &ps);
1554 return 0;
1558 static LRESULT
1559 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1561 TRACE("\n");
1562 infoPtr->bFocussed = TRUE;
1563 TRACKBAR_InvalidateAll(infoPtr);
1565 return 0;
1569 static LRESULT
1570 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1572 TRACKBAR_InitializeThumb (infoPtr);
1573 TRACKBAR_AlignBuddies (infoPtr);
1575 return 0;
1579 static LRESULT
1580 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1582 if (infoPtr->flags & TB_AUTO_PAGE) {
1583 POINT pt;
1584 if (GetCursorPos(&pt))
1585 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1586 TRACKBAR_AutoPage(infoPtr, pt);
1588 return 0;
1592 /* update theme after a WM_THEMECHANGED message */
1593 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1595 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1596 CloseThemeData (theme);
1597 OpenThemeData (infoPtr->hwndSelf, themeClass);
1598 return 0;
1602 static LRESULT
1603 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1605 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1606 INT clickPlace = (dwStyle & TBS_VERT) ? y : x;
1607 LONG dragPos, oldPos = infoPtr->lPos;
1609 TRACE("(x=%d. y=%d)\n", x, y);
1611 if (infoPtr->flags & TB_AUTO_PAGE) {
1612 POINT pt;
1613 pt.x = x;
1614 pt.y = y;
1615 TRACKBAR_AutoPage (infoPtr, pt);
1616 return TRUE;
1619 if (!(infoPtr->flags & TB_DRAG_MODE))
1621 if (GetWindowTheme (infoPtr->hwndSelf))
1623 DWORD oldFlags = infoPtr->flags;
1624 POINT pt;
1625 pt.x = x;
1626 pt.y = y;
1627 if (PtInRect (&infoPtr->rcThumb, pt))
1629 TRACKMOUSEEVENT tme;
1630 tme.cbSize = sizeof( tme );
1631 tme.dwFlags = TME_LEAVE;
1632 tme.hwndTrack = infoPtr->hwndSelf;
1633 TrackMouseEvent( &tme );
1634 infoPtr->flags |= TB_THUMB_HOT;
1636 else
1638 TRACKMOUSEEVENT tme;
1639 tme.cbSize = sizeof( tme );
1640 tme.dwFlags = TME_CANCEL;
1641 tme.hwndTrack = infoPtr->hwndSelf;
1642 TrackMouseEvent( &tme );
1643 infoPtr->flags &= ~TB_THUMB_HOT;
1645 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1647 return TRUE;
1650 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1651 dwStyle & TBS_VERT);
1652 if (dragPos == oldPos) return TRUE;
1654 infoPtr->lPos = dragPos;
1656 infoPtr->flags |= TB_THUMBPOSCHANGED;
1657 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1660 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1661 UpdateWindow (infoPtr->hwndSelf);
1663 return TRUE;
1666 static BOOL
1667 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1669 DWORD style = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1670 BOOL downIsLeft = style & TBS_DOWNISLEFT;
1671 BOOL vert = style & TBS_VERT;
1672 LONG pos = infoPtr->lPos;
1674 TRACE("%x\n", nVirtKey);
1676 switch (nVirtKey) {
1677 case VK_UP:
1678 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1679 else TRACKBAR_LineUp(infoPtr);
1680 break;
1681 case VK_LEFT:
1682 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1683 else TRACKBAR_LineUp(infoPtr);
1684 break;
1685 case VK_DOWN:
1686 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1687 else TRACKBAR_LineDown(infoPtr);
1688 break;
1689 case VK_RIGHT:
1690 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1691 else TRACKBAR_LineDown(infoPtr);
1692 break;
1693 case VK_NEXT:
1694 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1695 else TRACKBAR_PageDown(infoPtr);
1696 break;
1697 case VK_PRIOR:
1698 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1699 else TRACKBAR_PageUp(infoPtr);
1700 break;
1701 case VK_HOME:
1702 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1703 infoPtr->lPos = infoPtr->lRangeMin;
1704 notify_with_scroll (infoPtr, TB_TOP);
1705 break;
1706 case VK_END:
1707 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1708 infoPtr->lPos = infoPtr->lRangeMax;
1709 notify_with_scroll (infoPtr, TB_BOTTOM);
1710 break;
1713 if (pos != infoPtr->lPos) {
1714 infoPtr->flags |=TB_THUMBPOSCHANGED;
1715 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1718 return TRUE;
1722 static inline BOOL
1723 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1725 switch (nVirtKey) {
1726 case VK_LEFT:
1727 case VK_UP:
1728 case VK_RIGHT:
1729 case VK_DOWN:
1730 case VK_NEXT:
1731 case VK_PRIOR:
1732 case VK_HOME:
1733 case VK_END:
1734 notify_with_scroll (infoPtr, TB_ENDTRACK);
1736 return TRUE;
1740 static LRESULT WINAPI
1741 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1743 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1745 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1747 if (!infoPtr && (uMsg != WM_CREATE))
1748 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1750 switch (uMsg)
1752 case TBM_CLEARSEL:
1753 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1755 case TBM_CLEARTICS:
1756 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1758 case TBM_GETBUDDY:
1759 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1761 case TBM_GETCHANNELRECT:
1762 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1764 case TBM_GETLINESIZE:
1765 return infoPtr->lLineSize;
1767 case TBM_GETNUMTICS:
1768 return TRACKBAR_GetNumTics (infoPtr);
1770 case TBM_GETPAGESIZE:
1771 return infoPtr->lPageSize;
1773 case TBM_GETPOS:
1774 return infoPtr->lPos;
1776 case TBM_GETPTICS:
1777 return (LRESULT)infoPtr->tics;
1779 case TBM_GETRANGEMAX:
1780 return infoPtr->lRangeMax;
1782 case TBM_GETRANGEMIN:
1783 return infoPtr->lRangeMin;
1785 case TBM_GETSELEND:
1786 return infoPtr->lSelMax;
1788 case TBM_GETSELSTART:
1789 return infoPtr->lSelMin;
1791 case TBM_GETTHUMBLENGTH:
1792 return infoPtr->uThumbLen;
1794 case TBM_GETTHUMBRECT:
1795 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1797 case TBM_GETTIC:
1798 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1800 case TBM_GETTICPOS:
1801 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1803 case TBM_GETTOOLTIPS:
1804 return (LRESULT)infoPtr->hwndToolTip;
1806 case TBM_GETUNICODEFORMAT:
1807 return infoPtr->bUnicode;
1809 case TBM_SETBUDDY:
1810 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1812 case TBM_SETLINESIZE:
1813 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1815 case TBM_SETPAGESIZE:
1816 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1818 case TBM_SETPOS:
1819 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1821 case TBM_SETRANGE:
1822 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1824 case TBM_SETRANGEMAX:
1825 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1827 case TBM_SETRANGEMIN:
1828 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1830 case TBM_SETSEL:
1831 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1833 case TBM_SETSELEND:
1834 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1836 case TBM_SETSELSTART:
1837 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1839 case TBM_SETTHUMBLENGTH:
1840 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1842 case TBM_SETTIC:
1843 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1845 case TBM_SETTICFREQ:
1846 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1848 case TBM_SETTIPSIDE:
1849 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1851 case TBM_SETTOOLTIPS:
1852 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1854 case TBM_SETUNICODEFORMAT:
1855 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1858 case WM_CAPTURECHANGED:
1859 return TRACKBAR_CaptureChanged (infoPtr);
1861 case WM_CREATE:
1862 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1864 case WM_DESTROY:
1865 return TRACKBAR_Destroy (infoPtr);
1867 /* case WM_ENABLE: */
1869 case WM_ERASEBKGND:
1870 return 0;
1872 case WM_GETDLGCODE:
1873 return DLGC_WANTARROWS;
1875 case WM_KEYDOWN:
1876 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
1878 case WM_KEYUP:
1879 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
1881 case WM_KILLFOCUS:
1882 return TRACKBAR_KillFocus (infoPtr);
1884 case WM_LBUTTONDOWN:
1885 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1887 case WM_LBUTTONUP:
1888 return TRACKBAR_LButtonUp (infoPtr);
1890 case WM_MOUSELEAVE:
1891 infoPtr->flags &= ~TB_THUMB_HOT;
1892 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1893 return 0;
1895 case WM_MOUSEMOVE:
1896 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1898 case WM_PRINTCLIENT:
1899 case WM_PAINT:
1900 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1902 case WM_SETFOCUS:
1903 return TRACKBAR_SetFocus (infoPtr);
1905 case WM_SIZE:
1906 return TRACKBAR_Size (infoPtr);
1908 case WM_THEMECHANGED:
1909 return theme_changed (infoPtr);
1911 case WM_TIMER:
1912 return TRACKBAR_Timer (infoPtr);
1914 case WM_WININICHANGE:
1915 return TRACKBAR_InitializeThumb (infoPtr);
1917 default:
1918 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
1919 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
1920 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1925 void TRACKBAR_Register (void)
1927 WNDCLASSW wndClass;
1929 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1930 wndClass.style = CS_GLOBALCLASS;
1931 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1932 wndClass.cbClsExtra = 0;
1933 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1934 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1935 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1936 wndClass.lpszClassName = TRACKBAR_CLASSW;
1938 RegisterClassW (&wndClass);
1942 void TRACKBAR_Unregister (void)
1944 UnregisterClassW (TRACKBAR_CLASSW, NULL);