comctl32: Update thumb position on autopage instead of deferring it.
[wine/multimedia.git] / dlls / comctl32 / trackbar.c
blob99fde1b16b4318e554f4f100fa8537ddcaac9fb2
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 TRACKBAR_UpdateThumb (infoPtr);
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 redraw, LONG range)
1156 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1157 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1159 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1160 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1162 if (infoPtr->lPos < infoPtr->lRangeMin) {
1163 infoPtr->lPos = infoPtr->lRangeMin;
1164 infoPtr->flags |= TB_THUMBPOSCHANGED;
1167 if (infoPtr->lPos > infoPtr->lRangeMax) {
1168 infoPtr->lPos = infoPtr->lRangeMax;
1169 infoPtr->flags |= TB_THUMBPOSCHANGED;
1172 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1173 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1175 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1176 TRACKBAR_RecalculateTics (infoPtr);
1178 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1180 return 0;
1184 static inline LRESULT
1185 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1187 BOOL changed = infoPtr->lRangeMax != 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 (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1199 TRACKBAR_RecalculateTics (infoPtr);
1201 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1203 return 0;
1207 static inline LRESULT
1208 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1210 BOOL changed = infoPtr->lRangeMin != lMin;
1212 infoPtr->lRangeMin = lMin;
1213 if (infoPtr->lPos < infoPtr->lRangeMin) {
1214 infoPtr->lPos = infoPtr->lRangeMin;
1215 infoPtr->flags |= TB_THUMBPOSCHANGED;
1218 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1219 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1221 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1222 TRACKBAR_RecalculateTics (infoPtr);
1224 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1226 return 0;
1230 static inline LRESULT
1231 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1233 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1234 infoPtr->lSelMin = 0;
1235 infoPtr->lSelMax = 0;
1236 return 0;
1239 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1240 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1241 infoPtr->flags |= TB_SELECTIONCHANGED;
1243 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1244 infoPtr->lSelMin = infoPtr->lRangeMin;
1245 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1246 infoPtr->lSelMax = infoPtr->lRangeMax;
1248 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1250 return 0;
1254 static inline LRESULT
1255 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1257 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1258 infoPtr->lSelMax = 0;
1259 return 0;
1262 infoPtr->lSelMax = lEnd;
1263 infoPtr->flags |= TB_SELECTIONCHANGED;
1265 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1266 infoPtr->lSelMax = infoPtr->lRangeMax;
1268 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1270 return 0;
1274 static inline LRESULT
1275 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1277 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1278 infoPtr->lSelMin = 0;
1279 return 0;
1282 infoPtr->lSelMin = lStart;
1283 infoPtr->flags |=TB_SELECTIONCHANGED;
1285 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1286 infoPtr->lSelMin = infoPtr->lRangeMin;
1288 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1290 return 0;
1294 static inline LRESULT
1295 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1297 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1298 infoPtr->uThumbLen = iLength;
1299 infoPtr->flags |= TB_THUMBSIZECHANGED;
1300 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1303 return 0;
1307 static inline LRESULT
1308 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1310 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1311 return FALSE;
1313 TRACE("lPos=%d\n", lPos);
1315 infoPtr->uNumTics++;
1316 infoPtr->tics=ReAlloc( infoPtr->tics,
1317 (infoPtr->uNumTics)*sizeof (DWORD));
1318 if (!infoPtr->tics) {
1319 infoPtr->uNumTics = 0;
1320 notify(infoPtr, NM_OUTOFMEMORY);
1321 return FALSE;
1323 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1325 TRACKBAR_InvalidateAll(infoPtr);
1327 return TRUE;
1331 static inline LRESULT
1332 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1334 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1335 infoPtr->uTicFreq = wFreq;
1336 TRACKBAR_RecalculateTics (infoPtr);
1337 TRACKBAR_InvalidateAll(infoPtr);
1340 return 0;
1344 static inline INT
1345 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1347 INT fTemp = infoPtr->fLocation;
1349 infoPtr->fLocation = fLocation;
1351 return fTemp;
1355 static inline LRESULT
1356 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1358 infoPtr->hwndToolTip = hwndTT;
1360 return 0;
1364 static inline BOOL
1365 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1367 BOOL bTemp = infoPtr->bUnicode;
1369 infoPtr->bUnicode = fUnicode;
1371 return bTemp;
1375 static LRESULT
1376 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1378 RECT rect;
1379 int clientWidth, clientMetric;
1381 /* initial thumb length */
1382 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1383 GetClientRect(infoPtr->hwndSelf,&rect);
1384 if (infoPtr->dwStyle & TBS_VERT) {
1385 clientWidth = rect.right - rect.left;
1386 } else {
1387 clientWidth = rect.bottom - rect.top;
1389 if (clientWidth >= clientMetric)
1390 infoPtr->uThumbLen = clientMetric;
1391 else
1392 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1394 TRACKBAR_CalcChannel (infoPtr);
1395 TRACKBAR_UpdateThumb (infoPtr);
1396 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1398 return 0;
1402 static LRESULT
1403 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1405 TRACKBAR_INFO *infoPtr;
1407 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1408 if (!infoPtr) return -1;
1409 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1411 /* set default values */
1412 infoPtr->hwndSelf = hwnd;
1413 infoPtr->dwStyle = lpcs->style;
1414 infoPtr->lRangeMin = 0;
1415 infoPtr->lRangeMax = 100;
1416 infoPtr->lLineSize = 1;
1417 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1418 infoPtr->lSelMin = 0;
1419 infoPtr->lSelMax = 0;
1420 infoPtr->lPos = 0;
1421 infoPtr->fLocation = TBTS_TOP;
1422 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1423 infoPtr->uTicFreq = 1;
1424 infoPtr->tics = NULL;
1425 infoPtr->hwndNotify= lpcs->hwndParent;
1427 TRACKBAR_InitializeThumb (infoPtr);
1429 /* Create tooltip control */
1430 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1432 infoPtr->hwndToolTip =
1433 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1434 CW_USEDEFAULT, CW_USEDEFAULT,
1435 CW_USEDEFAULT, CW_USEDEFAULT,
1436 hwnd, 0, 0, 0);
1438 if (infoPtr->hwndToolTip) {
1439 TTTOOLINFOW ti;
1440 ZeroMemory (&ti, sizeof(ti));
1441 ti.cbSize = sizeof(ti);
1442 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1443 ti.hwnd = hwnd;
1445 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1449 OpenThemeData (hwnd, themeClass);
1451 return 0;
1455 static LRESULT
1456 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1458 /* delete tooltip control */
1459 if (infoPtr->hwndToolTip)
1460 DestroyWindow (infoPtr->hwndToolTip);
1462 Free (infoPtr->tics);
1463 infoPtr->tics = NULL;
1465 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1466 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1467 Free (infoPtr);
1469 return 0;
1473 static LRESULT
1474 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1476 TRACE("\n");
1477 infoPtr->bFocussed = FALSE;
1478 TRACKBAR_InvalidateAll(infoPtr);
1480 return 0;
1483 static LRESULT
1484 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1486 POINT clickPoint;
1488 clickPoint.x = x;
1489 clickPoint.y = y;
1491 SetFocus(infoPtr->hwndSelf);
1493 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1494 infoPtr->flags |= TB_DRAG_MODE;
1495 SetCapture (infoPtr->hwndSelf);
1496 TRACKBAR_UpdateToolTip (infoPtr);
1497 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1498 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1499 } else {
1500 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1501 if (dir == 0) return 0;
1502 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1503 TRACKBAR_AutoPage (infoPtr, clickPoint);
1504 SetCapture (infoPtr->hwndSelf);
1505 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1508 return 0;
1512 static LRESULT
1513 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1515 if (infoPtr->flags & TB_DRAG_MODE) {
1516 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1517 notify_with_scroll (infoPtr, TB_ENDTRACK);
1518 infoPtr->flags &= ~TB_DRAG_MODE;
1519 ReleaseCapture ();
1520 notify(infoPtr, NM_RELEASEDCAPTURE);
1521 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1522 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1524 if (infoPtr->flags & TB_AUTO_PAGE) {
1525 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1526 infoPtr->flags &= ~TB_AUTO_PAGE;
1527 notify_with_scroll (infoPtr, TB_ENDTRACK);
1528 ReleaseCapture ();
1529 notify(infoPtr, NM_RELEASEDCAPTURE);
1532 return 0;
1536 static LRESULT
1537 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1539 notify_with_scroll (infoPtr, TB_ENDTRACK);
1540 return 0;
1544 static LRESULT
1545 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1547 if (hdc) {
1548 TRACKBAR_Refresh(infoPtr, hdc);
1549 } else {
1550 PAINTSTRUCT ps;
1551 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1552 TRACKBAR_Refresh (infoPtr, hdc);
1553 EndPaint (infoPtr->hwndSelf, &ps);
1556 return 0;
1560 static LRESULT
1561 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1563 TRACE("\n");
1564 infoPtr->bFocussed = TRUE;
1565 TRACKBAR_InvalidateAll(infoPtr);
1567 return 0;
1571 static LRESULT
1572 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1574 TRACKBAR_CalcChannel (infoPtr);
1575 TRACKBAR_UpdateThumb (infoPtr);
1576 TRACKBAR_AlignBuddies (infoPtr);
1578 return 0;
1581 static LRESULT
1582 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1583 const STYLESTRUCT *lpss)
1585 if (wStyleType != GWL_STYLE) return 0;
1587 infoPtr->dwStyle = lpss->styleNew;
1589 return 0;
1592 static LRESULT
1593 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1595 if (infoPtr->flags & TB_AUTO_PAGE) {
1596 POINT pt;
1597 if (GetCursorPos(&pt))
1598 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1599 TRACKBAR_AutoPage(infoPtr, pt);
1601 return 0;
1605 /* update theme after a WM_THEMECHANGED message */
1606 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1608 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1609 CloseThemeData (theme);
1610 OpenThemeData (infoPtr->hwndSelf, themeClass);
1611 return 0;
1615 static LRESULT
1616 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1618 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1619 LONG dragPos, oldPos = infoPtr->lPos;
1621 TRACE("(x=%d. y=%d)\n", x, y);
1623 if (infoPtr->flags & TB_AUTO_PAGE) {
1624 POINT pt;
1625 pt.x = x;
1626 pt.y = y;
1627 TRACKBAR_AutoPage (infoPtr, pt);
1628 return TRUE;
1631 if (!(infoPtr->flags & TB_DRAG_MODE))
1633 if (GetWindowTheme (infoPtr->hwndSelf))
1635 DWORD oldFlags = infoPtr->flags;
1636 POINT pt;
1637 pt.x = x;
1638 pt.y = y;
1639 if (PtInRect (&infoPtr->rcThumb, pt))
1641 TRACKMOUSEEVENT tme;
1642 tme.cbSize = sizeof( tme );
1643 tme.dwFlags = TME_LEAVE;
1644 tme.hwndTrack = infoPtr->hwndSelf;
1645 TrackMouseEvent( &tme );
1646 infoPtr->flags |= TB_THUMB_HOT;
1648 else
1650 TRACKMOUSEEVENT tme;
1651 tme.cbSize = sizeof( tme );
1652 tme.dwFlags = TME_CANCEL;
1653 tme.hwndTrack = infoPtr->hwndSelf;
1654 TrackMouseEvent( &tme );
1655 infoPtr->flags &= ~TB_THUMB_HOT;
1657 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1659 return TRUE;
1662 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1664 if (dragPos == oldPos) return TRUE;
1666 infoPtr->lPos = dragPos;
1667 TRACKBAR_UpdateThumb (infoPtr);
1669 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1671 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1672 UpdateWindow (infoPtr->hwndSelf);
1674 return TRUE;
1677 static BOOL
1678 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1680 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1681 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1682 LONG pos = infoPtr->lPos;
1684 TRACE("%x\n", nVirtKey);
1686 switch (nVirtKey) {
1687 case VK_UP:
1688 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1689 else TRACKBAR_LineUp(infoPtr);
1690 break;
1691 case VK_LEFT:
1692 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1693 else TRACKBAR_LineUp(infoPtr);
1694 break;
1695 case VK_DOWN:
1696 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1697 else TRACKBAR_LineDown(infoPtr);
1698 break;
1699 case VK_RIGHT:
1700 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1701 else TRACKBAR_LineDown(infoPtr);
1702 break;
1703 case VK_NEXT:
1704 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1705 else TRACKBAR_PageDown(infoPtr);
1706 break;
1707 case VK_PRIOR:
1708 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1709 else TRACKBAR_PageUp(infoPtr);
1710 break;
1711 case VK_HOME:
1712 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1713 infoPtr->lPos = infoPtr->lRangeMin;
1714 notify_with_scroll (infoPtr, TB_TOP);
1715 break;
1716 case VK_END:
1717 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1718 infoPtr->lPos = infoPtr->lRangeMax;
1719 notify_with_scroll (infoPtr, TB_BOTTOM);
1720 break;
1723 if (pos != infoPtr->lPos) {
1724 infoPtr->flags |=TB_THUMBPOSCHANGED;
1725 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1728 return TRUE;
1732 static inline BOOL
1733 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1735 switch (nVirtKey) {
1736 case VK_LEFT:
1737 case VK_UP:
1738 case VK_RIGHT:
1739 case VK_DOWN:
1740 case VK_NEXT:
1741 case VK_PRIOR:
1742 case VK_HOME:
1743 case VK_END:
1744 notify_with_scroll (infoPtr, TB_ENDTRACK);
1746 return TRUE;
1750 static LRESULT WINAPI
1751 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1753 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1755 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1757 if (!infoPtr && (uMsg != WM_CREATE))
1758 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1760 switch (uMsg)
1762 case TBM_CLEARSEL:
1763 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1765 case TBM_CLEARTICS:
1766 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1768 case TBM_GETBUDDY:
1769 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1771 case TBM_GETCHANNELRECT:
1772 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1774 case TBM_GETLINESIZE:
1775 return infoPtr->lLineSize;
1777 case TBM_GETNUMTICS:
1778 return TRACKBAR_GetNumTics (infoPtr);
1780 case TBM_GETPAGESIZE:
1781 return infoPtr->lPageSize;
1783 case TBM_GETPOS:
1784 return infoPtr->lPos;
1786 case TBM_GETPTICS:
1787 return (LRESULT)infoPtr->tics;
1789 case TBM_GETRANGEMAX:
1790 return infoPtr->lRangeMax;
1792 case TBM_GETRANGEMIN:
1793 return infoPtr->lRangeMin;
1795 case TBM_GETSELEND:
1796 return infoPtr->lSelMax;
1798 case TBM_GETSELSTART:
1799 return infoPtr->lSelMin;
1801 case TBM_GETTHUMBLENGTH:
1802 return infoPtr->uThumbLen;
1804 case TBM_GETTHUMBRECT:
1805 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1807 case TBM_GETTIC:
1808 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1810 case TBM_GETTICPOS:
1811 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1813 case TBM_GETTOOLTIPS:
1814 return (LRESULT)infoPtr->hwndToolTip;
1816 case TBM_GETUNICODEFORMAT:
1817 return infoPtr->bUnicode;
1819 case TBM_SETBUDDY:
1820 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1822 case TBM_SETLINESIZE:
1823 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1825 case TBM_SETPAGESIZE:
1826 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1828 case TBM_SETPOS:
1829 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1831 case TBM_SETRANGE:
1832 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1834 case TBM_SETRANGEMAX:
1835 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1837 case TBM_SETRANGEMIN:
1838 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1840 case TBM_SETSEL:
1841 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1843 case TBM_SETSELEND:
1844 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1846 case TBM_SETSELSTART:
1847 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1849 case TBM_SETTHUMBLENGTH:
1850 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1852 case TBM_SETTIC:
1853 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1855 case TBM_SETTICFREQ:
1856 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1858 case TBM_SETTIPSIDE:
1859 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1861 case TBM_SETTOOLTIPS:
1862 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1864 case TBM_SETUNICODEFORMAT:
1865 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1868 case WM_CAPTURECHANGED:
1869 return TRACKBAR_CaptureChanged (infoPtr);
1871 case WM_CREATE:
1872 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1874 case WM_DESTROY:
1875 return TRACKBAR_Destroy (infoPtr);
1877 /* case WM_ENABLE: */
1879 case WM_ERASEBKGND:
1880 return 0;
1882 case WM_GETDLGCODE:
1883 return DLGC_WANTARROWS;
1885 case WM_KEYDOWN:
1886 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
1888 case WM_KEYUP:
1889 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
1891 case WM_KILLFOCUS:
1892 return TRACKBAR_KillFocus (infoPtr);
1894 case WM_LBUTTONDOWN:
1895 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1897 case WM_LBUTTONUP:
1898 return TRACKBAR_LButtonUp (infoPtr);
1900 case WM_MOUSELEAVE:
1901 infoPtr->flags &= ~TB_THUMB_HOT;
1902 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1903 return 0;
1905 case WM_MOUSEMOVE:
1906 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1908 case WM_PRINTCLIENT:
1909 case WM_PAINT:
1910 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1912 case WM_SETFOCUS:
1913 return TRACKBAR_SetFocus (infoPtr);
1915 case WM_SIZE:
1916 return TRACKBAR_Size (infoPtr);
1918 case WM_STYLECHANGED:
1919 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
1921 case WM_THEMECHANGED:
1922 return theme_changed (infoPtr);
1924 case WM_TIMER:
1925 return TRACKBAR_Timer (infoPtr);
1927 case WM_WININICHANGE:
1928 return TRACKBAR_InitializeThumb (infoPtr);
1930 default:
1931 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
1932 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
1933 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1938 void TRACKBAR_Register (void)
1940 WNDCLASSW wndClass;
1942 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1943 wndClass.style = CS_GLOBALCLASS;
1944 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1945 wndClass.cbClsExtra = 0;
1946 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1947 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1948 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1949 wndClass.lpszClassName = TRACKBAR_CLASSW;
1951 RegisterClassW (&wndClass);
1955 void TRACKBAR_Unregister (void)
1957 UnregisterClassW (TRACKBAR_CLASSW, NULL);