comctl32: Update ticks on TBM_SETRANGEMIN.
[wine/multimedia.git] / dlls / comctl32 / trackbar.c
blob679d9793e06eebae8404c1ece02512692a6f1392
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 "vssym32.h"
46 #include "wine/debug.h"
48 #include "comctl32.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
52 typedef struct
54 HWND hwndSelf;
55 DWORD dwStyle;
56 LONG lRangeMin;
57 LONG lRangeMax;
58 LONG lLineSize;
59 LONG lPageSize;
60 LONG lSelMin;
61 LONG lSelMax;
62 LONG lPos;
63 UINT uThumbLen;
64 UINT uNumTics;
65 UINT uTicFreq;
66 HWND hwndNotify;
67 HWND hwndToolTip;
68 HWND hwndBuddyLA;
69 HWND hwndBuddyRB;
70 INT fLocation;
71 INT flags;
72 BOOL bUnicode;
73 BOOL bFocussed;
74 RECT rcChannel;
75 RECT rcSelection;
76 RECT rcThumb;
77 LPLONG tics;
78 } TRACKBAR_INFO;
80 #define TB_REFRESH_TIMER 1
81 #define TB_REFRESH_DELAY 500
83 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
85 #define TB_DEFAULTPAGESIZE 20
87 /* Used by TRACKBAR_Refresh to find out which parts of the control
88 need to be recalculated */
90 #define TB_THUMBPOSCHANGED 1
91 #define TB_THUMBSIZECHANGED 2
92 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
93 #define TB_SELECTIONCHANGED 4
94 #define TB_DRAG_MODE 8 /* we're dragging the slider */
95 #define TB_AUTO_PAGE_LEFT 16
96 #define TB_AUTO_PAGE_RIGHT 32
97 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
98 #define TB_THUMB_HOT 64 /* mouse hovers above thumb */
100 /* helper defines for TRACKBAR_DrawTic */
101 #define TIC_EDGE 0x20
102 #define TIC_SELECTIONMARKMAX 0x80
103 #define TIC_SELECTIONMARKMIN 0x100
104 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
106 static const WCHAR themeClass[] = { 'T','r','a','c','k','b','a','r',0 };
108 static inline int
109 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
111 pnmcd->dwDrawStage = stage;
112 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
113 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
116 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
118 LRESULT result;
120 TRACE("(code=%d)\n", code);
122 pnmh->hwndFrom = infoPtr->hwndSelf;
123 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
124 pnmh->code = code;
125 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
127 TRACE(" <= %ld\n", result);
129 return result;
132 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
134 NMHDR nmh;
135 return notify_hdr(infoPtr, code, &nmh);
138 static void notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
140 UINT scroll = infoPtr->dwStyle & TBS_VERT ? WM_VSCROLL : WM_HSCROLL;
142 TRACE("%x\n", code);
144 SendMessageW (infoPtr->hwndNotify, scroll, code, (LPARAM)infoPtr->hwndSelf);
147 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
149 int tic;
150 unsigned nrTics, i;
152 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin) {
153 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
154 /* don't add extra tic if there's no remainder */
155 if (nrTics && ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0))
156 nrTics--;
158 else {
159 Free (infoPtr->tics);
160 infoPtr->tics = NULL;
161 infoPtr->uNumTics = 0;
162 return;
165 if (nrTics != infoPtr->uNumTics) {
166 infoPtr->tics=ReAlloc (infoPtr->tics,
167 (nrTics+1)*sizeof (DWORD));
168 if (!infoPtr->tics) {
169 infoPtr->uNumTics = 0;
170 notify(infoPtr, NM_OUTOFMEMORY);
171 return;
173 infoPtr->uNumTics = nrTics;
176 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
177 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
178 infoPtr->tics[i] = tic;
181 /* converts from physical (mouse) position to logical position
182 (in range of trackbar) */
184 static inline LONG
185 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place)
187 double range, width, pos, offsetthumb;
189 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
190 if (infoPtr->dwStyle & TBS_VERT) {
191 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
192 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
193 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
194 } else {
195 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
196 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
197 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
199 pos += infoPtr->lRangeMin;
200 if (pos > infoPtr->lRangeMax)
201 pos = infoPtr->lRangeMax;
202 else if (pos < infoPtr->lRangeMin)
203 pos = infoPtr->lRangeMin;
205 TRACE("%.2f\n", pos);
206 return (LONG)(pos + 0.5);
210 /* return: 0> prev, 0 none, >0 next */
211 static LONG
212 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
214 RECT pageRect;
216 if (infoPtr->dwStyle & TBS_VERT) {
217 pageRect.top = infoPtr->rcChannel.top;
218 pageRect.bottom = infoPtr->rcChannel.bottom;
219 pageRect.left = infoPtr->rcThumb.left;
220 pageRect.right = infoPtr->rcThumb.right;
221 } else {
222 pageRect.top = infoPtr->rcThumb.top;
223 pageRect.bottom = infoPtr->rcThumb.bottom;
224 pageRect.left = infoPtr->rcChannel.left;
225 pageRect.right = infoPtr->rcChannel.right;
229 if (PtInRect(&pageRect, clickPoint))
231 int clickPlace = (infoPtr->dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
233 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace);
235 return clickPos - infoPtr->lPos;
238 return 0;
241 static inline void
242 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
244 if (infoPtr->lPos == infoPtr->lRangeMax) return;
246 infoPtr->lPos += infoPtr->lPageSize;
247 if (infoPtr->lPos > infoPtr->lRangeMax)
248 infoPtr->lPos = infoPtr->lRangeMax;
249 notify_with_scroll (infoPtr, TB_PAGEDOWN);
253 static inline void
254 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
256 if (infoPtr->lPos == infoPtr->lRangeMin) return;
258 infoPtr->lPos -= infoPtr->lPageSize;
259 if (infoPtr->lPos < infoPtr->lRangeMin)
260 infoPtr->lPos = infoPtr->lRangeMin;
261 notify_with_scroll (infoPtr, TB_PAGEUP);
264 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
266 if (infoPtr->lPos == infoPtr->lRangeMin) return;
267 infoPtr->lPos -= infoPtr->lLineSize;
268 if (infoPtr->lPos < infoPtr->lRangeMin)
269 infoPtr->lPos = infoPtr->lRangeMin;
270 notify_with_scroll (infoPtr, TB_LINEUP);
273 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
275 if (infoPtr->lPos == infoPtr->lRangeMax) return;
276 infoPtr->lPos += infoPtr->lLineSize;
277 if (infoPtr->lPos > infoPtr->lRangeMax)
278 infoPtr->lPos = infoPtr->lRangeMax;
279 notify_with_scroll (infoPtr, TB_LINEDOWN);
282 static void
283 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
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 = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
293 if (infoPtr->dwStyle & TBS_VERT) {
294 channel->top = lpRect.top + offsetedge;
295 channel->bottom = lpRect.bottom - offsetedge;
296 if (infoPtr->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 (infoPtr->dwStyle & TBS_BOTH) {
301 if (infoPtr->dwStyle & TBS_NOTICKS)
302 channel->left += 1;
303 else
304 channel->left += 9;
306 else if (infoPtr->dwStyle & TBS_TOP) {
307 if (infoPtr->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 (infoPtr->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 (infoPtr->dwStyle & TBS_BOTH) {
321 if (infoPtr->dwStyle & TBS_NOTICKS)
322 channel->top += 1;
323 else
324 channel->top += 9;
326 else if (infoPtr->dwStyle & TBS_TOP) {
327 if (infoPtr->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 RECT lpRect;
342 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
343 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
345 if (!range) range = 1;
347 GetClientRect(infoPtr->hwndSelf, &lpRect);
348 if (infoPtr->dwStyle & TBS_VERT)
350 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
352 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_LEFT)) && !(infoPtr->dwStyle & TBS_NOTICKS))
353 thumb->left = 10;
354 else
355 thumb->left = 2;
356 thumb->right = thumb->left + infoPtr->uThumbLen;
357 thumb->top = infoPtr->rcChannel.top +
358 (height*(lPos - infoPtr->lRangeMin))/range;
359 thumb->bottom = thumb->top + thumbwidth;
361 else
363 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
365 thumb->left = infoPtr->rcChannel.left +
366 (width*(lPos - infoPtr->lRangeMin))/range;
367 thumb->right = thumb->left + thumbwidth;
368 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_TOP)) && !(infoPtr->dwStyle & TBS_NOTICKS))
369 thumb->top = 10;
370 else
371 thumb->top = 2;
372 thumb->bottom = thumb->top + infoPtr->uThumbLen;
376 static inline void
377 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
379 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
382 static inline void
383 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
385 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
388 static void
389 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
391 RECT rcThumb;
393 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
394 InflateRect(&rcThumb, 1, 1);
395 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
398 static inline void
399 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
401 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
402 if (newPos != oldPos)
403 TRACKBAR_InvalidateThumb (infoPtr, newPos);
406 static inline BOOL
407 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
409 return infoPtr->lSelMin != infoPtr->lSelMax;
412 static void
413 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
415 RECT *selection = &infoPtr->rcSelection;
416 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
417 int offsetthumb, height, width;
419 if (range <= 0) {
420 SetRectEmpty (selection);
421 } else {
422 if (infoPtr->dwStyle & TBS_VERT) {
423 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
424 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
425 selection->top = infoPtr->rcChannel.top + offsetthumb +
426 (height*infoPtr->lSelMin)/range;
427 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
428 (height*infoPtr->lSelMax)/range;
429 selection->left = infoPtr->rcChannel.left + 3;
430 selection->right = infoPtr->rcChannel.right - 3;
431 } else {
432 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
433 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
434 selection->left = infoPtr->rcChannel.left + offsetthumb +
435 (width*infoPtr->lSelMin)/range;
436 selection->right = infoPtr->rcChannel.left + offsetthumb +
437 (width*infoPtr->lSelMax)/range;
438 selection->top = infoPtr->rcChannel.top + 3;
439 selection->bottom = infoPtr->rcChannel.bottom - 3;
443 TRACE("selection[%s]\n", wine_dbgstr_rect(selection));
446 static BOOL
447 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
449 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
450 LONG prevPos = infoPtr->lPos;
452 TRACE("x=%d, y=%d, dir=%d\n", clickPoint.x, clickPoint.y, dir);
454 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
455 TRACKBAR_PageDown(infoPtr);
456 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
457 TRACKBAR_PageUp(infoPtr);
458 else return FALSE;
460 infoPtr->flags |= TB_THUMBPOSCHANGED;
461 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
463 return TRUE;
466 /* Trackbar drawing code. I like my spaghetti done milanese. */
468 static void
469 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc)
471 RECT rcChannel = infoPtr->rcChannel;
472 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
474 if (theme)
476 DrawThemeBackground (theme, hdc,
477 (infoPtr->dwStyle & TBS_VERT) ?
478 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
480 else
482 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
483 if (infoPtr->dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
484 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
485 if (TRACKBAR_HasSelection(infoPtr))
486 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
491 static void
492 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
494 int x, y, ox, oy, range, side, indent = 0, len = 3;
495 int offsetthumb;
496 RECT rcTics;
498 if (flags & TBS_VERT) {
499 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
500 rcTics.left = infoPtr->rcThumb.left - 2;
501 rcTics.right = infoPtr->rcThumb.right + 2;
502 rcTics.top = infoPtr->rcChannel.top + offsetthumb + 1;
503 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb;
504 } else {
505 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
506 rcTics.left = infoPtr->rcChannel.left + offsetthumb + 1;
507 rcTics.right = infoPtr->rcChannel.right - offsetthumb;
508 rcTics.top = infoPtr->rcThumb.top - 2;
509 rcTics.bottom = infoPtr->rcThumb.bottom + 2;
512 if (flags & (TBS_TOP | TBS_LEFT)) {
513 x = rcTics.left;
514 y = rcTics.top;
515 side = -1;
516 } else {
517 x = rcTics.right;
518 y = rcTics.bottom;
519 side = 1;
522 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
523 if (range <= 0)
524 range = 1; /* to avoid division by zero */
526 if (flags & TIC_SELECTIONMARK) {
527 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
528 } else if (flags & TIC_EDGE) {
529 len++;
532 if (flags & TBS_VERT) {
533 int height = rcTics.bottom - rcTics.top;
534 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
535 } else {
536 int width = rcTics.right - rcTics.left;
537 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
540 ox = x;
541 oy = y;
542 MoveToEx(hdc, x, y, 0);
543 if (flags & TBS_VERT) x += len * side;
544 else y += len * side;
545 LineTo(hdc, x, y);
547 if (flags & TIC_SELECTIONMARK) {
548 if (flags & TBS_VERT) {
549 x -= side;
550 } else {
551 y -= side;
553 MoveToEx(hdc, x, y, 0);
554 if (flags & TBS_VERT) {
555 y += 2 * indent;
556 } else {
557 x += 2 * indent;
560 LineTo(hdc, x, y);
561 LineTo(hdc, ox, oy);
566 static inline void
567 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
569 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
570 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
572 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
573 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
576 static void
577 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc)
579 unsigned int i;
580 int ticFlags = infoPtr->dwStyle & 0x0f;
581 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
582 HPEN hOldPen, hTicPen;
583 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
585 if (theme)
587 int part = (infoPtr->dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
588 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
590 /* create the pen to draw the tics with */
591 hTicPen = CreatePenIndirect(&ticPen);
592 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
594 /* actually draw the tics */
595 for (i=0; i<infoPtr->uNumTics; i++)
596 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
599 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
601 if ((infoPtr->dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
602 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
603 ticFlags | TIC_SELECTIONMARKMIN);
604 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
605 ticFlags | TIC_SELECTIONMARKMAX);
608 /* clean up the pen, if we created one */
609 if (hTicPen) {
610 SelectObject(hdc, hOldPen);
611 DeleteObject(hTicPen);
615 static void
616 TRACKBAR_DrawThumb (const TRACKBAR_INFO *infoPtr, HDC hdc)
618 HBRUSH oldbr;
619 HPEN oldpen;
620 RECT thumb = infoPtr->rcThumb;
621 int BlackUntil = 3;
622 int PointCount = 6;
623 POINT points[6];
624 int fillClr;
625 int PointDepth;
626 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
628 if (theme)
630 int partId;
631 int stateId;
632 if (infoPtr->dwStyle & TBS_BOTH)
633 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
634 else if (infoPtr->dwStyle & TBS_LEFT)
635 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
636 else
637 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
639 if (infoPtr->dwStyle & WS_DISABLED)
640 stateId = TUS_DISABLED;
641 else if (infoPtr->flags & TB_DRAG_MODE)
642 stateId = TUS_PRESSED;
643 else if (infoPtr->flags & TB_THUMB_HOT)
644 stateId = TUS_HOT;
645 else
646 stateId = TUS_NORMAL;
648 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
650 return;
653 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
654 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
655 SetPolyFillMode (hdc, WINDING);
657 if (infoPtr->dwStyle & TBS_BOTH)
659 points[0].x=thumb.right;
660 points[0].y=thumb.top;
661 points[1].x=thumb.right;
662 points[1].y=thumb.bottom;
663 points[2].x=thumb.left;
664 points[2].y=thumb.bottom;
665 points[3].x=thumb.left;
666 points[3].y=thumb.top;
667 points[4].x=points[0].x;
668 points[4].y=points[0].y;
669 PointCount = 5;
670 BlackUntil = 3;
672 else
674 if (infoPtr->dwStyle & TBS_VERT)
676 PointDepth = (thumb.bottom - thumb.top) / 2;
677 if (infoPtr->dwStyle & TBS_LEFT)
679 points[0].x=thumb.right;
680 points[0].y=thumb.top;
681 points[1].x=thumb.right;
682 points[1].y=thumb.bottom;
683 points[2].x=thumb.left + PointDepth;
684 points[2].y=thumb.bottom;
685 points[3].x=thumb.left;
686 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
687 points[4].x=thumb.left + PointDepth;
688 points[4].y=thumb.top;
689 points[5].x=points[0].x;
690 points[5].y=points[0].y;
691 BlackUntil = 4;
693 else
695 points[0].x=thumb.right;
696 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
697 points[1].x=thumb.right - PointDepth;
698 points[1].y=thumb.bottom;
699 points[2].x=thumb.left;
700 points[2].y=thumb.bottom;
701 points[3].x=thumb.left;
702 points[3].y=thumb.top;
703 points[4].x=thumb.right - PointDepth;
704 points[4].y=thumb.top;
705 points[5].x=points[0].x;
706 points[5].y=points[0].y;
709 else
711 PointDepth = (thumb.right - thumb.left) / 2;
712 if (infoPtr->dwStyle & TBS_TOP)
714 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
715 points[0].y=thumb.top;
716 points[1].x=thumb.right;
717 points[1].y=thumb.top + PointDepth;
718 points[2].x=thumb.right;
719 points[2].y=thumb.bottom;
720 points[3].x=thumb.left;
721 points[3].y=thumb.bottom;
722 points[4].x=thumb.left;
723 points[4].y=thumb.top + PointDepth;
724 points[5].x=points[0].x;
725 points[5].y=points[0].y;
726 BlackUntil = 4;
728 else
730 points[0].x=thumb.right;
731 points[0].y=thumb.top;
732 points[1].x=thumb.right;
733 points[1].y=thumb.bottom - PointDepth;
734 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
735 points[2].y=thumb.bottom;
736 points[3].x=thumb.left;
737 points[3].y=thumb.bottom - PointDepth;
738 points[4].x=thumb.left;
739 points[4].y=thumb.top;
740 points[5].x=points[0].x;
741 points[5].y=points[0].y;
747 /* Draw the thumb now */
748 Polygon (hdc, points, PointCount);
749 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
750 Polyline(hdc,points, BlackUntil);
751 SelectObject(hdc, GetStockObject(WHITE_PEN));
752 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
753 SelectObject(hdc, oldpen);
754 SelectObject(hdc, oldbr);
758 static inline void
759 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
761 TTTOOLINFOW ti;
763 if (!infoPtr->hwndToolTip) return;
765 ZeroMemory(&ti, sizeof(ti));
766 ti.cbSize = sizeof(ti);
767 ti.hwnd = infoPtr->hwndSelf;
769 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
773 static void
774 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
776 WCHAR buf[80];
777 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
778 TTTOOLINFOW ti;
779 POINT pt;
780 RECT rcClient;
781 LRESULT size;
783 if (!infoPtr->hwndToolTip) return;
785 ZeroMemory(&ti, sizeof(ti));
786 ti.cbSize = sizeof(ti);
787 ti.hwnd = infoPtr->hwndSelf;
788 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
790 wsprintfW (buf, fmt, infoPtr->lPos);
791 ti.lpszText = buf;
792 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
794 GetClientRect (infoPtr->hwndSelf, &rcClient);
795 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
796 if (infoPtr->dwStyle & TBS_VERT) {
797 if (infoPtr->fLocation == TBTS_LEFT)
798 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
799 else
800 pt.x = rcClient.right + TOOLTIP_OFFSET;
801 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
802 } else {
803 if (infoPtr->fLocation == TBTS_TOP)
804 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
805 else
806 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
807 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
809 ClientToScreen(infoPtr->hwndSelf, &pt);
811 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
812 0, MAKELPARAM(pt.x, pt.y));
816 static void
817 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
819 RECT rcClient;
820 HDC hdc;
821 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
822 NMCUSTOMDRAW nmcd;
823 int gcdrf, icdrf;
825 if (infoPtr->flags & TB_THUMBCHANGED) {
826 TRACKBAR_UpdateThumb (infoPtr);
827 if (infoPtr->flags & TB_THUMBSIZECHANGED)
828 TRACKBAR_CalcChannel (infoPtr);
830 if (infoPtr->flags & TB_SELECTIONCHANGED)
831 TRACKBAR_CalcSelection (infoPtr);
833 if (infoPtr->flags & TB_DRAG_MODE)
834 TRACKBAR_UpdateToolTip (infoPtr);
836 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
838 GetClientRect (infoPtr->hwndSelf, &rcClient);
840 /* try to render offscreen, if we fail, carrry onscreen */
841 hdc = CreateCompatibleDC(hdcDst);
842 if (hdc) {
843 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
844 if (hOffScreenBmp) {
845 hOldBmp = SelectObject(hdc, hOffScreenBmp);
846 } else {
847 DeleteObject(hdc);
848 hdc = hdcDst;
850 } else {
851 hdc = hdcDst;
854 ZeroMemory(&nmcd, sizeof(nmcd));
855 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
856 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
857 nmcd.hdr.code = NM_CUSTOMDRAW;
858 nmcd.hdc = hdc;
860 /* start the paint cycle */
861 nmcd.rc = rcClient;
862 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
863 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
865 /* Erase background */
866 if (gcdrf == CDRF_DODEFAULT ||
867 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
868 if (GetWindowTheme (infoPtr->hwndSelf)) {
869 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
871 else
872 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
873 if (gcdrf != CDRF_DODEFAULT)
874 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
877 /* draw channel */
878 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
879 nmcd.dwItemSpec = TBCD_CHANNEL;
880 nmcd.uItemState = CDIS_DEFAULT;
881 nmcd.rc = infoPtr->rcChannel;
882 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
883 } else icdrf = CDRF_DODEFAULT;
884 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
885 TRACKBAR_DrawChannel (infoPtr, hdc);
886 if (icdrf & CDRF_NOTIFYPOSTPAINT)
887 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
891 /* draw tics */
892 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
893 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
894 nmcd.dwItemSpec = TBCD_TICS;
895 nmcd.uItemState = CDIS_DEFAULT;
896 nmcd.rc = rcClient;
897 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
898 } else icdrf = CDRF_DODEFAULT;
899 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
900 TRACKBAR_DrawTics (infoPtr, hdc);
901 if (icdrf & CDRF_NOTIFYPOSTPAINT)
902 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
906 /* draw thumb */
907 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
908 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
909 nmcd.dwItemSpec = TBCD_THUMB;
910 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
911 nmcd.rc = infoPtr->rcThumb;
912 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
913 } else icdrf = CDRF_DODEFAULT;
914 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
915 TRACKBAR_DrawThumb(infoPtr, hdc);
916 if (icdrf & CDRF_NOTIFYPOSTPAINT)
917 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
921 /* draw focus rectangle */
922 if (infoPtr->bFocussed) {
923 DrawFocusRect(hdc, &rcClient);
926 /* finish up the painting */
927 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
928 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
930 cleanup:
931 /* cleanup, if we rendered offscreen */
932 if (hdc != hdcDst) {
933 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
934 SelectObject(hdc, hOldBmp);
935 DeleteObject(hOffScreenBmp);
936 DeleteObject(hdc);
941 static void
942 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
944 HWND hwndParent = GetParent (infoPtr->hwndSelf);
945 RECT rcSelf, rcBuddy;
946 INT x, y;
948 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
949 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
951 /* align buddy left or above */
952 if (infoPtr->hwndBuddyLA) {
953 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
954 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
956 if (infoPtr->dwStyle & TBS_VERT) {
957 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
958 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
959 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
961 else {
962 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
963 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
964 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
967 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
968 SWP_NOZORDER | SWP_NOSIZE);
972 /* align buddy right or below */
973 if (infoPtr->hwndBuddyRB) {
974 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
975 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
977 if (infoPtr->dwStyle & TBS_VERT) {
978 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
979 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
980 y = rcSelf.bottom;
982 else {
983 x = rcSelf.right;
984 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
985 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
987 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
988 SWP_NOZORDER | SWP_NOSIZE);
993 static LRESULT
994 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
996 infoPtr->lSelMin = 0;
997 infoPtr->lSelMax = 0;
998 infoPtr->flags |= TB_SELECTIONCHANGED;
1000 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1002 return 0;
1006 static LRESULT
1007 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1009 if (infoPtr->tics) {
1010 Free (infoPtr->tics);
1011 infoPtr->tics = NULL;
1012 infoPtr->uNumTics = 0;
1015 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1017 return 0;
1021 static inline LRESULT
1022 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1024 if (lprc == NULL) return 0;
1026 lprc->left = infoPtr->rcChannel.left;
1027 lprc->right = infoPtr->rcChannel.right;
1028 lprc->bottom = infoPtr->rcChannel.bottom;
1029 lprc->top = infoPtr->rcChannel.top;
1031 return 0;
1035 static inline LONG
1036 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1038 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1040 return infoPtr->uNumTics + 2;
1044 static int comp_tics (const void *ap, const void *bp)
1046 const DWORD a = *(const DWORD *)ap;
1047 const DWORD b = *(const DWORD *)bp;
1049 TRACE("(a=%d, b=%d)\n", a, b);
1050 if (a < b) return -1;
1051 if (a > b) return 1;
1052 return 0;
1056 static inline LONG
1057 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1059 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1060 return -1;
1062 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1063 return infoPtr->tics[iTic];
1067 static inline LONG
1068 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1070 LONG range, width, pos, tic;
1071 int offsetthumb;
1073 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1074 return -1;
1076 tic = TRACKBAR_GetTic (infoPtr, iTic);
1077 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1078 if (range <= 0) range = 1;
1079 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1080 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1081 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1083 return pos;
1087 static HWND
1088 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1090 HWND hwndTemp;
1092 if (fLocation) {
1093 /* buddy is left or above */
1094 hwndTemp = infoPtr->hwndBuddyLA;
1095 infoPtr->hwndBuddyLA = hwndBuddy;
1097 else {
1098 /* buddy is right or below */
1099 hwndTemp = infoPtr->hwndBuddyRB;
1100 infoPtr->hwndBuddyRB = hwndBuddy;
1103 TRACKBAR_AlignBuddies (infoPtr);
1105 return hwndTemp;
1109 static inline LONG
1110 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1112 LONG lTemp = infoPtr->lLineSize;
1114 infoPtr->lLineSize = lLineSize;
1116 return lTemp;
1120 static inline LONG
1121 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1123 LONG lTemp = infoPtr->lPageSize;
1125 if (lPageSize != -1)
1126 infoPtr->lPageSize = lPageSize;
1127 else
1128 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1130 return lTemp;
1134 static inline LRESULT
1135 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1137 LONG oldPos = infoPtr->lPos;
1138 infoPtr->lPos = lPosition;
1140 if (infoPtr->lPos < infoPtr->lRangeMin)
1141 infoPtr->lPos = infoPtr->lRangeMin;
1143 if (infoPtr->lPos > infoPtr->lRangeMax)
1144 infoPtr->lPos = infoPtr->lRangeMax;
1145 infoPtr->flags |= TB_THUMBPOSCHANGED;
1147 if (fPosition && oldPos != lPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1149 return 0;
1153 static inline LRESULT
1154 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1156 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1157 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1159 if (infoPtr->lPos < infoPtr->lRangeMin) {
1160 infoPtr->lPos = infoPtr->lRangeMin;
1161 infoPtr->flags |= TB_THUMBPOSCHANGED;
1164 if (infoPtr->lPos > infoPtr->lRangeMax) {
1165 infoPtr->lPos = infoPtr->lRangeMax;
1166 infoPtr->flags |= TB_THUMBPOSCHANGED;
1169 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1170 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1172 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1174 return 0;
1178 static inline LRESULT
1179 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1181 BOOL changed = infoPtr->lRangeMax != lMax;
1183 infoPtr->lRangeMax = lMax;
1184 if (infoPtr->lPos > infoPtr->lRangeMax) {
1185 infoPtr->lPos = infoPtr->lRangeMax;
1186 infoPtr->flags |= TB_THUMBPOSCHANGED;
1189 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1190 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1192 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1193 TRACKBAR_RecalculateTics (infoPtr);
1195 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1197 return 0;
1201 static inline LRESULT
1202 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1204 BOOL changed = infoPtr->lRangeMin != lMin;
1206 infoPtr->lRangeMin = lMin;
1207 if (infoPtr->lPos < infoPtr->lRangeMin) {
1208 infoPtr->lPos = infoPtr->lRangeMin;
1209 infoPtr->flags |= TB_THUMBPOSCHANGED;
1212 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1213 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1215 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1216 TRACKBAR_RecalculateTics (infoPtr);
1218 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1220 return 0;
1224 static inline LRESULT
1225 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1227 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1228 infoPtr->lSelMin = 0;
1229 infoPtr->lSelMax = 0;
1230 return 0;
1233 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1234 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1235 infoPtr->flags |= TB_SELECTIONCHANGED;
1237 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1238 infoPtr->lSelMin = infoPtr->lRangeMin;
1239 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1240 infoPtr->lSelMax = infoPtr->lRangeMax;
1242 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1244 return 0;
1248 static inline LRESULT
1249 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1251 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1252 infoPtr->lSelMax = 0;
1253 return 0;
1256 infoPtr->lSelMax = lEnd;
1257 infoPtr->flags |= TB_SELECTIONCHANGED;
1259 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1260 infoPtr->lSelMax = infoPtr->lRangeMax;
1262 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1264 return 0;
1268 static inline LRESULT
1269 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1271 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1272 infoPtr->lSelMin = 0;
1273 return 0;
1276 infoPtr->lSelMin = lStart;
1277 infoPtr->flags |=TB_SELECTIONCHANGED;
1279 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1280 infoPtr->lSelMin = infoPtr->lRangeMin;
1282 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1284 return 0;
1288 static inline LRESULT
1289 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1291 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1292 infoPtr->uThumbLen = iLength;
1293 infoPtr->flags |= TB_THUMBSIZECHANGED;
1294 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1297 return 0;
1301 static inline LRESULT
1302 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1304 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1305 return FALSE;
1307 TRACE("lPos=%d\n", lPos);
1309 infoPtr->uNumTics++;
1310 infoPtr->tics=ReAlloc( infoPtr->tics,
1311 (infoPtr->uNumTics)*sizeof (DWORD));
1312 if (!infoPtr->tics) {
1313 infoPtr->uNumTics = 0;
1314 notify(infoPtr, NM_OUTOFMEMORY);
1315 return FALSE;
1317 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1319 TRACKBAR_InvalidateAll(infoPtr);
1321 return TRUE;
1325 static inline LRESULT
1326 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1328 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1329 infoPtr->uTicFreq = wFreq;
1330 TRACKBAR_RecalculateTics (infoPtr);
1331 TRACKBAR_InvalidateAll(infoPtr);
1334 return 0;
1338 static inline INT
1339 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1341 INT fTemp = infoPtr->fLocation;
1343 infoPtr->fLocation = fLocation;
1345 return fTemp;
1349 static inline LRESULT
1350 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1352 infoPtr->hwndToolTip = hwndTT;
1354 return 0;
1358 static inline BOOL
1359 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1361 BOOL bTemp = infoPtr->bUnicode;
1363 infoPtr->bUnicode = fUnicode;
1365 return bTemp;
1369 static LRESULT
1370 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1372 RECT rect;
1373 int clientWidth, clientMetric;
1375 /* initial thumb length */
1376 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1377 GetClientRect(infoPtr->hwndSelf,&rect);
1378 if (infoPtr->dwStyle & TBS_VERT) {
1379 clientWidth = rect.right - rect.left;
1380 } else {
1381 clientWidth = rect.bottom - rect.top;
1383 if (clientWidth >= clientMetric)
1384 infoPtr->uThumbLen = clientMetric;
1385 else
1386 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1388 TRACKBAR_CalcChannel (infoPtr);
1389 TRACKBAR_UpdateThumb (infoPtr);
1390 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1392 return 0;
1396 static LRESULT
1397 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1399 TRACKBAR_INFO *infoPtr;
1401 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1402 if (!infoPtr) return -1;
1403 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1405 /* set default values */
1406 infoPtr->hwndSelf = hwnd;
1407 infoPtr->dwStyle = lpcs->style;
1408 infoPtr->lRangeMin = 0;
1409 infoPtr->lRangeMax = 100;
1410 infoPtr->lLineSize = 1;
1411 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1412 infoPtr->lSelMin = 0;
1413 infoPtr->lSelMax = 0;
1414 infoPtr->lPos = 0;
1415 infoPtr->fLocation = TBTS_TOP;
1416 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1417 infoPtr->uTicFreq = 1;
1418 infoPtr->tics = NULL;
1419 infoPtr->hwndNotify= lpcs->hwndParent;
1421 TRACKBAR_InitializeThumb (infoPtr);
1423 /* Create tooltip control */
1424 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1426 infoPtr->hwndToolTip =
1427 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1428 CW_USEDEFAULT, CW_USEDEFAULT,
1429 CW_USEDEFAULT, CW_USEDEFAULT,
1430 hwnd, 0, 0, 0);
1432 if (infoPtr->hwndToolTip) {
1433 TTTOOLINFOW ti;
1434 ZeroMemory (&ti, sizeof(ti));
1435 ti.cbSize = sizeof(ti);
1436 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1437 ti.hwnd = hwnd;
1439 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1443 OpenThemeData (hwnd, themeClass);
1445 return 0;
1449 static LRESULT
1450 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1452 /* delete tooltip control */
1453 if (infoPtr->hwndToolTip)
1454 DestroyWindow (infoPtr->hwndToolTip);
1456 Free (infoPtr->tics);
1457 infoPtr->tics = NULL;
1459 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1460 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1461 Free (infoPtr);
1463 return 0;
1467 static LRESULT
1468 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1470 TRACE("\n");
1471 infoPtr->bFocussed = FALSE;
1472 TRACKBAR_InvalidateAll(infoPtr);
1474 return 0;
1477 static LRESULT
1478 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1480 POINT clickPoint;
1482 clickPoint.x = x;
1483 clickPoint.y = y;
1485 SetFocus(infoPtr->hwndSelf);
1487 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1488 infoPtr->flags |= TB_DRAG_MODE;
1489 SetCapture (infoPtr->hwndSelf);
1490 TRACKBAR_UpdateToolTip (infoPtr);
1491 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1492 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1493 } else {
1494 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1495 if (dir == 0) return 0;
1496 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1497 TRACKBAR_AutoPage (infoPtr, clickPoint);
1498 SetCapture (infoPtr->hwndSelf);
1499 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1502 return 0;
1506 static LRESULT
1507 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1509 if (infoPtr->flags & TB_DRAG_MODE) {
1510 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1511 notify_with_scroll (infoPtr, TB_ENDTRACK);
1512 infoPtr->flags &= ~TB_DRAG_MODE;
1513 ReleaseCapture ();
1514 notify(infoPtr, NM_RELEASEDCAPTURE);
1515 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1516 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1518 if (infoPtr->flags & TB_AUTO_PAGE) {
1519 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1520 infoPtr->flags &= ~TB_AUTO_PAGE;
1521 notify_with_scroll (infoPtr, TB_ENDTRACK);
1522 ReleaseCapture ();
1523 notify(infoPtr, NM_RELEASEDCAPTURE);
1526 return 0;
1530 static LRESULT
1531 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1533 notify_with_scroll (infoPtr, TB_ENDTRACK);
1534 return 0;
1538 static LRESULT
1539 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1541 if (hdc) {
1542 TRACKBAR_Refresh(infoPtr, hdc);
1543 } else {
1544 PAINTSTRUCT ps;
1545 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1546 TRACKBAR_Refresh (infoPtr, hdc);
1547 EndPaint (infoPtr->hwndSelf, &ps);
1550 return 0;
1554 static LRESULT
1555 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1557 TRACE("\n");
1558 infoPtr->bFocussed = TRUE;
1559 TRACKBAR_InvalidateAll(infoPtr);
1561 return 0;
1565 static LRESULT
1566 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1568 TRACKBAR_CalcChannel (infoPtr);
1569 TRACKBAR_UpdateThumb (infoPtr);
1570 TRACKBAR_AlignBuddies (infoPtr);
1572 return 0;
1575 static LRESULT
1576 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1577 const STYLESTRUCT *lpss)
1579 if (wStyleType != GWL_STYLE) return 0;
1581 infoPtr->dwStyle = lpss->styleNew;
1583 return 0;
1586 static LRESULT
1587 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1589 if (infoPtr->flags & TB_AUTO_PAGE) {
1590 POINT pt;
1591 if (GetCursorPos(&pt))
1592 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1593 TRACKBAR_AutoPage(infoPtr, pt);
1595 return 0;
1599 /* update theme after a WM_THEMECHANGED message */
1600 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1602 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1603 CloseThemeData (theme);
1604 OpenThemeData (infoPtr->hwndSelf, themeClass);
1605 return 0;
1609 static LRESULT
1610 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1612 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1613 LONG dragPos, oldPos = infoPtr->lPos;
1615 TRACE("(x=%d. y=%d)\n", x, y);
1617 if (infoPtr->flags & TB_AUTO_PAGE) {
1618 POINT pt;
1619 pt.x = x;
1620 pt.y = y;
1621 TRACKBAR_AutoPage (infoPtr, pt);
1622 return TRUE;
1625 if (!(infoPtr->flags & TB_DRAG_MODE))
1627 if (GetWindowTheme (infoPtr->hwndSelf))
1629 DWORD oldFlags = infoPtr->flags;
1630 POINT pt;
1631 pt.x = x;
1632 pt.y = y;
1633 if (PtInRect (&infoPtr->rcThumb, pt))
1635 TRACKMOUSEEVENT tme;
1636 tme.cbSize = sizeof( tme );
1637 tme.dwFlags = TME_LEAVE;
1638 tme.hwndTrack = infoPtr->hwndSelf;
1639 TrackMouseEvent( &tme );
1640 infoPtr->flags |= TB_THUMB_HOT;
1642 else
1644 TRACKMOUSEEVENT tme;
1645 tme.cbSize = sizeof( tme );
1646 tme.dwFlags = TME_CANCEL;
1647 tme.hwndTrack = infoPtr->hwndSelf;
1648 TrackMouseEvent( &tme );
1649 infoPtr->flags &= ~TB_THUMB_HOT;
1651 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1653 return TRUE;
1656 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1658 if (dragPos == oldPos) return TRUE;
1660 infoPtr->lPos = dragPos;
1662 infoPtr->flags |= TB_THUMBPOSCHANGED;
1663 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1666 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1667 UpdateWindow (infoPtr->hwndSelf);
1669 return TRUE;
1672 static BOOL
1673 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1675 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1676 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1677 LONG pos = infoPtr->lPos;
1679 TRACE("%x\n", nVirtKey);
1681 switch (nVirtKey) {
1682 case VK_UP:
1683 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1684 else TRACKBAR_LineUp(infoPtr);
1685 break;
1686 case VK_LEFT:
1687 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1688 else TRACKBAR_LineUp(infoPtr);
1689 break;
1690 case VK_DOWN:
1691 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1692 else TRACKBAR_LineDown(infoPtr);
1693 break;
1694 case VK_RIGHT:
1695 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1696 else TRACKBAR_LineDown(infoPtr);
1697 break;
1698 case VK_NEXT:
1699 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1700 else TRACKBAR_PageDown(infoPtr);
1701 break;
1702 case VK_PRIOR:
1703 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1704 else TRACKBAR_PageUp(infoPtr);
1705 break;
1706 case VK_HOME:
1707 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1708 infoPtr->lPos = infoPtr->lRangeMin;
1709 notify_with_scroll (infoPtr, TB_TOP);
1710 break;
1711 case VK_END:
1712 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1713 infoPtr->lPos = infoPtr->lRangeMax;
1714 notify_with_scroll (infoPtr, TB_BOTTOM);
1715 break;
1718 if (pos != infoPtr->lPos) {
1719 infoPtr->flags |=TB_THUMBPOSCHANGED;
1720 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1723 return TRUE;
1727 static inline BOOL
1728 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1730 switch (nVirtKey) {
1731 case VK_LEFT:
1732 case VK_UP:
1733 case VK_RIGHT:
1734 case VK_DOWN:
1735 case VK_NEXT:
1736 case VK_PRIOR:
1737 case VK_HOME:
1738 case VK_END:
1739 notify_with_scroll (infoPtr, TB_ENDTRACK);
1741 return TRUE;
1745 static LRESULT WINAPI
1746 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1748 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1750 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1752 if (!infoPtr && (uMsg != WM_CREATE))
1753 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1755 switch (uMsg)
1757 case TBM_CLEARSEL:
1758 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1760 case TBM_CLEARTICS:
1761 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1763 case TBM_GETBUDDY:
1764 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1766 case TBM_GETCHANNELRECT:
1767 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1769 case TBM_GETLINESIZE:
1770 return infoPtr->lLineSize;
1772 case TBM_GETNUMTICS:
1773 return TRACKBAR_GetNumTics (infoPtr);
1775 case TBM_GETPAGESIZE:
1776 return infoPtr->lPageSize;
1778 case TBM_GETPOS:
1779 return infoPtr->lPos;
1781 case TBM_GETPTICS:
1782 return (LRESULT)infoPtr->tics;
1784 case TBM_GETRANGEMAX:
1785 return infoPtr->lRangeMax;
1787 case TBM_GETRANGEMIN:
1788 return infoPtr->lRangeMin;
1790 case TBM_GETSELEND:
1791 return infoPtr->lSelMax;
1793 case TBM_GETSELSTART:
1794 return infoPtr->lSelMin;
1796 case TBM_GETTHUMBLENGTH:
1797 return infoPtr->uThumbLen;
1799 case TBM_GETTHUMBRECT:
1800 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1802 case TBM_GETTIC:
1803 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1805 case TBM_GETTICPOS:
1806 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1808 case TBM_GETTOOLTIPS:
1809 return (LRESULT)infoPtr->hwndToolTip;
1811 case TBM_GETUNICODEFORMAT:
1812 return infoPtr->bUnicode;
1814 case TBM_SETBUDDY:
1815 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1817 case TBM_SETLINESIZE:
1818 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1820 case TBM_SETPAGESIZE:
1821 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1823 case TBM_SETPOS:
1824 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1826 case TBM_SETRANGE:
1827 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1829 case TBM_SETRANGEMAX:
1830 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1832 case TBM_SETRANGEMIN:
1833 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1835 case TBM_SETSEL:
1836 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1838 case TBM_SETSELEND:
1839 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1841 case TBM_SETSELSTART:
1842 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1844 case TBM_SETTHUMBLENGTH:
1845 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1847 case TBM_SETTIC:
1848 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1850 case TBM_SETTICFREQ:
1851 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1853 case TBM_SETTIPSIDE:
1854 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1856 case TBM_SETTOOLTIPS:
1857 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1859 case TBM_SETUNICODEFORMAT:
1860 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1863 case WM_CAPTURECHANGED:
1864 return TRACKBAR_CaptureChanged (infoPtr);
1866 case WM_CREATE:
1867 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1869 case WM_DESTROY:
1870 return TRACKBAR_Destroy (infoPtr);
1872 /* case WM_ENABLE: */
1874 case WM_ERASEBKGND:
1875 return 0;
1877 case WM_GETDLGCODE:
1878 return DLGC_WANTARROWS;
1880 case WM_KEYDOWN:
1881 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
1883 case WM_KEYUP:
1884 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
1886 case WM_KILLFOCUS:
1887 return TRACKBAR_KillFocus (infoPtr);
1889 case WM_LBUTTONDOWN:
1890 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1892 case WM_LBUTTONUP:
1893 return TRACKBAR_LButtonUp (infoPtr);
1895 case WM_MOUSELEAVE:
1896 infoPtr->flags &= ~TB_THUMB_HOT;
1897 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1898 return 0;
1900 case WM_MOUSEMOVE:
1901 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1903 case WM_PRINTCLIENT:
1904 case WM_PAINT:
1905 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1907 case WM_SETFOCUS:
1908 return TRACKBAR_SetFocus (infoPtr);
1910 case WM_SIZE:
1911 return TRACKBAR_Size (infoPtr);
1913 case WM_STYLECHANGED:
1914 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
1916 case WM_THEMECHANGED:
1917 return theme_changed (infoPtr);
1919 case WM_TIMER:
1920 return TRACKBAR_Timer (infoPtr);
1922 case WM_WININICHANGE:
1923 return TRACKBAR_InitializeThumb (infoPtr);
1925 default:
1926 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
1927 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
1928 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1933 void TRACKBAR_Register (void)
1935 WNDCLASSW wndClass;
1937 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1938 wndClass.style = CS_GLOBALCLASS;
1939 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1940 wndClass.cbClsExtra = 0;
1941 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1942 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1943 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1944 wndClass.lpszClassName = TRACKBAR_CLASSW;
1946 RegisterClassW (&wndClass);
1950 void TRACKBAR_Unregister (void)
1952 UnregisterClassW (TRACKBAR_CLASSW, NULL);