ntoskrnl.exe/tests: Add some IOCTL_HID_WRITE_REPORT tests.
[wine.git] / dlls / comctl32 / trackbar.c
blobce6a20c6c637906d2d86c57add7715e4950d6cde
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
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <math.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "commctrl.h"
35 #include "uxtheme.h"
36 #include "vssym32.h"
37 #include "wine/debug.h"
39 #include "comctl32.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
43 typedef struct
45 HWND hwndSelf;
46 DWORD dwStyle;
47 LONG lRangeMin;
48 LONG lRangeMax;
49 LONG lLineSize;
50 LONG lPageSize;
51 LONG lSelMin;
52 LONG lSelMax;
53 LONG lPos;
54 UINT uThumbLen;
55 UINT uNumTics;
56 UINT uTicFreq;
57 HWND hwndNotify;
58 HWND hwndToolTip;
59 HWND hwndBuddyLA;
60 HWND hwndBuddyRB;
61 INT fLocation;
62 DWORD flags;
63 BOOL bUnicode;
64 RECT rcChannel;
65 RECT rcSelection;
66 RECT rcThumb;
67 LPLONG tics;
68 } TRACKBAR_INFO;
70 #define TB_REFRESH_TIMER 1
71 #define TB_REFRESH_DELAY 500
73 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
75 #define TB_DEFAULTPAGESIZE 20
77 /* Used by TRACKBAR_Refresh to find out which parts of the control
78 need to be recalculated */
80 #define TB_THUMBPOSCHANGED 0x00000001
81 #define TB_THUMBSIZECHANGED 0x00000002
82 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
83 #define TB_SELECTIONCHANGED 0x00000004
84 #define TB_DRAG_MODE 0x00000008 /* we're dragging the slider */
85 #define TB_AUTO_PAGE_LEFT 0x00000010
86 #define TB_AUTO_PAGE_RIGHT 0x00000020
87 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
88 #define TB_THUMB_HOT 0x00000040 /* mouse hovers above thumb */
90 /* Page was set with TBM_SETPAGESIZE */
91 #define TB_USER_PAGE 0x00000080
92 #define TB_IS_FOCUSED 0x00000100
94 /* helper defines for TRACKBAR_DrawTic */
95 #define TIC_EDGE 0x20
96 #define TIC_SELECTIONMARKMAX 0x80
97 #define TIC_SELECTIONMARKMIN 0x100
98 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
100 static const WCHAR themeClass[] = L"Trackbar";
102 static inline int
103 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
105 pnmcd->dwDrawStage = stage;
106 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
107 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
110 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
112 LRESULT result;
114 TRACE("(code=%d)\n", code);
116 pnmh->hwndFrom = infoPtr->hwndSelf;
117 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
118 pnmh->code = code;
119 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
121 TRACE(" <= %ld\n", result);
123 return result;
126 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
128 NMHDR nmh;
129 return notify_hdr(infoPtr, code, &nmh);
132 static void notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
134 UINT scroll = infoPtr->dwStyle & TBS_VERT ? WM_VSCROLL : WM_HSCROLL;
136 TRACE("%x\n", code);
138 SendMessageW (infoPtr->hwndNotify, scroll, code, (LPARAM)infoPtr->hwndSelf);
141 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
143 int tic;
144 unsigned nrTics, i;
146 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin) {
147 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
148 /* don't add extra tic if there's no remainder */
149 if (nrTics && ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0))
150 nrTics--;
152 else {
153 Free (infoPtr->tics);
154 infoPtr->tics = NULL;
155 infoPtr->uNumTics = 0;
156 return;
159 if (nrTics != infoPtr->uNumTics) {
160 infoPtr->tics=ReAlloc (infoPtr->tics,
161 (nrTics+1)*sizeof (DWORD));
162 if (!infoPtr->tics) {
163 infoPtr->uNumTics = 0;
164 notify(infoPtr, NM_OUTOFMEMORY);
165 return;
167 infoPtr->uNumTics = nrTics;
170 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
171 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
172 infoPtr->tics[i] = tic;
175 /* converts from physical (mouse) position to logical position
176 (in range of trackbar) */
178 static inline LONG
179 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place)
181 double range, width, pos, offsetthumb;
183 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
184 if (infoPtr->dwStyle & TBS_VERT) {
185 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
186 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
187 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
188 } else {
189 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
190 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
191 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
193 pos += infoPtr->lRangeMin;
194 if (pos > infoPtr->lRangeMax)
195 pos = infoPtr->lRangeMax;
196 else if (pos < infoPtr->lRangeMin)
197 pos = infoPtr->lRangeMin;
199 TRACE("%.2f\n", pos);
200 return (LONG)floor(pos + 0.5);
204 /* return: 0> prev, 0 none, >0 next */
205 static LONG
206 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
208 RECT pageRect;
210 if (infoPtr->dwStyle & TBS_VERT) {
211 pageRect.top = infoPtr->rcChannel.top;
212 pageRect.bottom = infoPtr->rcChannel.bottom;
213 pageRect.left = infoPtr->rcThumb.left;
214 pageRect.right = infoPtr->rcThumb.right;
215 } else {
216 pageRect.top = infoPtr->rcThumb.top;
217 pageRect.bottom = infoPtr->rcThumb.bottom;
218 pageRect.left = infoPtr->rcChannel.left;
219 pageRect.right = infoPtr->rcChannel.right;
223 if (PtInRect(&pageRect, clickPoint))
225 int clickPlace = (infoPtr->dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
227 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace);
229 return clickPos - infoPtr->lPos;
232 return 0;
235 static inline void
236 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
238 if (infoPtr->lPos == infoPtr->lRangeMax) return;
240 infoPtr->lPos += infoPtr->lPageSize;
241 if (infoPtr->lPos > infoPtr->lRangeMax)
242 infoPtr->lPos = infoPtr->lRangeMax;
243 notify_with_scroll (infoPtr, TB_PAGEDOWN);
247 static inline void
248 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
250 if (infoPtr->lPos == infoPtr->lRangeMin) return;
252 infoPtr->lPos -= infoPtr->lPageSize;
253 if (infoPtr->lPos < infoPtr->lRangeMin)
254 infoPtr->lPos = infoPtr->lRangeMin;
255 notify_with_scroll (infoPtr, TB_PAGEUP);
258 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
260 if (infoPtr->lPos == infoPtr->lRangeMin) return;
261 infoPtr->lPos -= infoPtr->lLineSize;
262 if (infoPtr->lPos < infoPtr->lRangeMin)
263 infoPtr->lPos = infoPtr->lRangeMin;
264 notify_with_scroll (infoPtr, TB_LINEUP);
267 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
269 if (infoPtr->lPos == infoPtr->lRangeMax) return;
270 infoPtr->lPos += infoPtr->lLineSize;
271 if (infoPtr->lPos > infoPtr->lRangeMax)
272 infoPtr->lPos = infoPtr->lRangeMax;
273 notify_with_scroll (infoPtr, TB_LINEDOWN);
276 static void
277 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
279 INT cyChannel, offsetthumb, offsetedge;
280 RECT lpRect, *channel = & infoPtr->rcChannel;
282 GetClientRect (infoPtr->hwndSelf, &lpRect);
284 offsetthumb = infoPtr->uThumbLen / 4;
285 offsetedge = offsetthumb + 3;
286 cyChannel = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
287 if (infoPtr->dwStyle & TBS_VERT) {
288 channel->top = lpRect.top + offsetedge;
289 channel->bottom = lpRect.bottom - offsetedge;
290 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
291 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
292 else
293 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
294 if (infoPtr->dwStyle & TBS_BOTH) {
295 if (infoPtr->dwStyle & TBS_NOTICKS)
296 channel->left += 1;
297 else
298 channel->left += 9;
300 else if (infoPtr->dwStyle & TBS_TOP) {
301 if (infoPtr->dwStyle & TBS_NOTICKS)
302 channel->left += 2;
303 else
304 channel->left += 10;
306 channel->right = channel->left + cyChannel;
307 } else {
308 channel->left = lpRect.left + offsetedge;
309 channel->right = lpRect.right - offsetedge;
310 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
311 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
312 else
313 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
314 if (infoPtr->dwStyle & TBS_BOTH) {
315 if (infoPtr->dwStyle & TBS_NOTICKS)
316 channel->top += 1;
317 else
318 channel->top += 9;
320 else if (infoPtr->dwStyle & TBS_TOP) {
321 if (infoPtr->dwStyle & TBS_NOTICKS)
322 channel->top += 2;
323 else
324 channel->top += 10;
326 channel->bottom = channel->top + cyChannel;
330 static void
331 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
333 int range, width, height, thumbwidth;
334 RECT lpRect;
336 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
337 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
339 if (!range) range = 1;
341 GetClientRect(infoPtr->hwndSelf, &lpRect);
342 if (infoPtr->dwStyle & TBS_VERT)
344 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
346 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_LEFT)) && !(infoPtr->dwStyle & TBS_NOTICKS))
347 thumb->left = 10;
348 else
349 thumb->left = 2;
350 thumb->right = thumb->left + infoPtr->uThumbLen;
351 thumb->top = infoPtr->rcChannel.top +
352 (height*(lPos - infoPtr->lRangeMin))/range;
353 thumb->bottom = thumb->top + thumbwidth;
355 else
357 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
359 thumb->left = infoPtr->rcChannel.left +
360 (width*(lPos - infoPtr->lRangeMin))/range;
361 thumb->right = thumb->left + thumbwidth;
362 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_TOP)) && !(infoPtr->dwStyle & TBS_NOTICKS))
363 thumb->top = 10;
364 else
365 thumb->top = 2;
366 thumb->bottom = thumb->top + infoPtr->uThumbLen;
370 static inline void
371 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
373 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
376 static inline void
377 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
379 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
382 static void
383 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
385 RECT rcThumb;
387 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
388 InflateRect(&rcThumb, 1, 1);
389 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
392 static inline void
393 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
395 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
396 if (newPos != oldPos)
397 TRACKBAR_InvalidateThumb (infoPtr, newPos);
400 static inline BOOL
401 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
403 return infoPtr->lSelMin != infoPtr->lSelMax;
406 static void
407 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
409 RECT *selection = &infoPtr->rcSelection;
410 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
411 int offsetthumb, height, width;
413 if (range <= 0) {
414 SetRectEmpty (selection);
415 } else {
416 if (infoPtr->dwStyle & TBS_VERT) {
417 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
418 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
419 selection->top = infoPtr->rcChannel.top + offsetthumb +
420 (height*infoPtr->lSelMin)/range;
421 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
422 (height*infoPtr->lSelMax)/range;
423 selection->left = infoPtr->rcChannel.left + 3;
424 selection->right = infoPtr->rcChannel.right - 3;
425 } else {
426 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
427 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
428 selection->left = infoPtr->rcChannel.left + offsetthumb +
429 (width*infoPtr->lSelMin)/range;
430 selection->right = infoPtr->rcChannel.left + offsetthumb +
431 (width*infoPtr->lSelMax)/range;
432 selection->top = infoPtr->rcChannel.top + 3;
433 selection->bottom = infoPtr->rcChannel.bottom - 3;
437 TRACE("selection[%s]\n", wine_dbgstr_rect(selection));
440 static BOOL
441 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
443 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
444 LONG prevPos = infoPtr->lPos;
446 TRACE("clickPoint=%s, dir=%d\n", wine_dbgstr_point(&clickPoint), dir);
448 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
449 TRACKBAR_PageDown(infoPtr);
450 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
451 TRACKBAR_PageUp(infoPtr);
452 else return FALSE;
454 TRACKBAR_UpdateThumb (infoPtr);
455 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
457 return TRUE;
460 /* Trackbar drawing code. I like my spaghetti done milanese. */
462 static void
463 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc)
465 RECT rcChannel = infoPtr->rcChannel;
466 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
468 if (theme)
470 DrawThemeBackground (theme, hdc,
471 (infoPtr->dwStyle & TBS_VERT) ?
472 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
474 else
476 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
477 if (infoPtr->dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
478 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
479 if (TRACKBAR_HasSelection(infoPtr))
480 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
485 static void
486 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
488 int x, y, ox, oy, range, side, indent = 0, len = 3;
489 int offsetthumb;
490 RECT rcTics;
492 if (flags & TBS_VERT) {
493 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
494 SetRect(&rcTics, infoPtr->rcThumb.left - 2, infoPtr->rcChannel.top + offsetthumb,
495 infoPtr->rcThumb.right + 2, infoPtr->rcChannel.bottom - offsetthumb - 1);
496 } else {
497 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
498 SetRect(&rcTics, infoPtr->rcChannel.left + offsetthumb, infoPtr->rcThumb.top - 2,
499 infoPtr->rcChannel.right - offsetthumb - 1, infoPtr->rcThumb.bottom + 2);
502 if (flags & (TBS_TOP | TBS_LEFT)) {
503 x = rcTics.left;
504 y = rcTics.top;
505 side = -1;
506 } else {
507 x = rcTics.right;
508 y = rcTics.bottom;
509 side = 1;
512 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
513 if (range <= 0)
514 range = 1; /* to avoid division by zero */
516 if (flags & TIC_SELECTIONMARK) {
517 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
518 } else if (flags & TIC_EDGE) {
519 len++;
522 if (flags & TBS_VERT) {
523 int height = rcTics.bottom - rcTics.top;
524 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
525 } else {
526 int width = rcTics.right - rcTics.left;
527 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
530 ox = x;
531 oy = y;
532 MoveToEx(hdc, x, y, 0);
533 if (flags & TBS_VERT) x += len * side;
534 else y += len * side;
535 LineTo(hdc, x, y);
537 if (flags & TIC_SELECTIONMARK) {
538 if (flags & TBS_VERT) {
539 x -= side;
540 } else {
541 y -= side;
543 MoveToEx(hdc, x, y, 0);
544 if (flags & TBS_VERT) {
545 y += 2 * indent;
546 } else {
547 x += 2 * indent;
550 LineTo(hdc, x, y);
551 LineTo(hdc, ox, oy);
556 static inline void
557 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
559 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
560 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
562 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
563 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
566 static void
567 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc)
569 unsigned int i;
570 int ticFlags = infoPtr->dwStyle & 0x0f;
571 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
572 HPEN hOldPen, hTicPen;
573 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
575 if (theme)
577 int part = (infoPtr->dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
578 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
580 /* create the pen to draw the tics with */
581 hTicPen = CreatePenIndirect(&ticPen);
582 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
584 /* actually draw the tics */
585 for (i=0; i<infoPtr->uNumTics; i++)
586 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
588 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
589 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
591 if ((infoPtr->dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
592 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
593 ticFlags | TIC_SELECTIONMARKMIN);
594 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
595 ticFlags | TIC_SELECTIONMARKMAX);
598 /* clean up the pen, if we created one */
599 if (hTicPen) {
600 SelectObject(hdc, hOldPen);
601 DeleteObject(hTicPen);
605 static int
606 TRACKBAR_FillThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, HBRUSH hbrush)
608 const RECT *thumb = &infoPtr->rcThumb;
609 POINT points[6];
610 int PointDepth;
611 HBRUSH oldbr;
613 if (infoPtr->dwStyle & TBS_BOTH)
615 FillRect(hdc, thumb, hbrush);
616 return 0;
619 if (infoPtr->dwStyle & TBS_VERT)
621 PointDepth = (thumb->bottom - thumb->top) / 2;
622 if (infoPtr->dwStyle & TBS_LEFT)
624 points[0].x = thumb->right-1;
625 points[0].y = thumb->top;
626 points[1].x = thumb->right-1;
627 points[1].y = thumb->bottom-1;
628 points[2].x = thumb->left + PointDepth;
629 points[2].y = thumb->bottom-1;
630 points[3].x = thumb->left;
631 points[3].y = thumb->top + PointDepth;
632 points[4].x = thumb->left + PointDepth;
633 points[4].y = thumb->top;
634 points[5].x = points[0].x;
635 points[5].y = points[0].y;
637 else
639 points[0].x = thumb->right;
640 points[0].y = thumb->top + PointDepth;
641 points[1].x = thumb->right - PointDepth;
642 points[1].y = thumb->bottom-1;
643 points[2].x = thumb->left;
644 points[2].y = thumb->bottom-1;
645 points[3].x = thumb->left;
646 points[3].y = thumb->top;
647 points[4].x = thumb->right - PointDepth;
648 points[4].y = thumb->top;
649 points[5].x = points[0].x;
650 points[5].y = points[0].y;
653 else
655 PointDepth = (thumb->right - thumb->left) / 2;
656 if (infoPtr->dwStyle & TBS_TOP)
658 points[0].x = thumb->left + PointDepth;
659 points[0].y = thumb->top+1;
660 points[1].x = thumb->right-1;
661 points[1].y = thumb->top + PointDepth + 1;
662 points[2].x = thumb->right-1;
663 points[2].y = thumb->bottom-1;
664 points[3].x = thumb->left;
665 points[3].y = thumb->bottom-1;
666 points[4].x = thumb->left;
667 points[4].y = thumb->top + PointDepth + 1;
668 points[5].x = points[0].x;
669 points[5].y = points[0].y;
671 else
673 points[0].x = thumb->right-1;
674 points[0].y = thumb->top;
675 points[1].x = thumb->right-1;
676 points[1].y = thumb->bottom - PointDepth - 1;
677 points[2].x = thumb->left + PointDepth;
678 points[2].y = thumb->bottom-1;
679 points[3].x = thumb->left;
680 points[3].y = thumb->bottom - PointDepth - 1;
681 points[4].x = thumb->left;
682 points[4].y = thumb->top;
683 points[5].x = points[0].x;
684 points[5].y = points[0].y;
688 oldbr = SelectObject(hdc, hbrush);
689 SetPolyFillMode(hdc, WINDING);
690 Polygon(hdc, points, ARRAY_SIZE(points));
691 SelectObject(hdc, oldbr);
693 return PointDepth;
696 static void
697 TRACKBAR_DrawThumb (TRACKBAR_INFO *infoPtr, HDC hdc)
699 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
700 int PointDepth;
701 HBRUSH brush;
703 if (theme)
705 int partId;
706 int stateId;
707 if (infoPtr->dwStyle & TBS_BOTH)
708 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
709 else if (infoPtr->dwStyle & TBS_LEFT)
710 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
711 else
712 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
714 if (infoPtr->dwStyle & WS_DISABLED)
715 stateId = TUS_DISABLED;
716 else if (infoPtr->flags & TB_DRAG_MODE)
717 stateId = TUS_PRESSED;
718 else if (infoPtr->flags & TB_THUMB_HOT)
719 stateId = TUS_HOT;
720 else if (infoPtr->flags & TB_IS_FOCUSED)
721 stateId = TUS_FOCUSED;
722 else
723 stateId = TUS_NORMAL;
725 DrawThemeBackground (theme, hdc, partId, stateId, &infoPtr->rcThumb, NULL);
727 return;
730 if (infoPtr->dwStyle & WS_DISABLED || infoPtr->flags & TB_DRAG_MODE)
732 if (comctl32_color.clr3dHilight == comctl32_color.clrWindow)
733 brush = COMCTL32_hPattern55AABrush;
734 else
735 brush = GetSysColorBrush(COLOR_SCROLLBAR);
737 SetTextColor(hdc, comctl32_color.clr3dFace);
738 SetBkColor(hdc, comctl32_color.clr3dHilight);
740 else
741 brush = GetSysColorBrush(COLOR_BTNFACE);
743 PointDepth = TRACKBAR_FillThumb(infoPtr, hdc, brush);
745 if (infoPtr->dwStyle & TBS_BOTH)
747 DrawEdge(hdc, &infoPtr->rcThumb, EDGE_RAISED, BF_RECT | BF_SOFT);
748 return;
750 else
752 RECT thumb = infoPtr->rcThumb;
754 if (infoPtr->dwStyle & TBS_VERT)
756 if (infoPtr->dwStyle & TBS_LEFT)
758 /* rectangular part */
759 thumb.left += PointDepth;
760 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_RIGHT | BF_BOTTOM | BF_SOFT);
762 /* light edge */
763 thumb.left -= PointDepth;
764 thumb.right = thumb.left + PointDepth;
765 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
766 thumb.top = infoPtr->rcThumb.top;
767 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
769 /* shadowed edge */
770 thumb.top += PointDepth;
771 thumb.bottom += PointDepth;
772 DrawEdge(hdc, &thumb, EDGE_SUNKEN, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
773 return;
775 else
777 /* rectangular part */
778 thumb.right -= PointDepth;
779 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_LEFT | BF_BOTTOM | BF_SOFT);
781 /* light edge */
782 thumb.left = thumb.right;
783 thumb.right += PointDepth + 1;
784 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
785 thumb.top = infoPtr->rcThumb.top;
786 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
788 /* shadowed edge */
789 thumb.top += PointDepth;
790 thumb.bottom += PointDepth;
791 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
794 else
796 if (infoPtr->dwStyle & TBS_TOP)
798 /* rectangular part */
799 thumb.top += PointDepth;
800 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_BOTTOM | BF_RIGHT | BF_SOFT);
802 /* light edge */
803 thumb.left = infoPtr->rcThumb.left;
804 thumb.right = thumb.left + PointDepth;
805 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
806 thumb.top -= PointDepth;
807 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
809 /* shadowed edge */
810 thumb.left += PointDepth;
811 thumb.right += PointDepth;
812 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMRIGHT | BF_SOFT);
814 else
816 /* rectangular part */
817 thumb.bottom -= PointDepth;
818 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT);
820 /* light edge */
821 thumb.left = infoPtr->rcThumb.left;
822 thumb.right = thumb.left + PointDepth;
823 thumb.top = infoPtr->rcThumb.bottom - PointDepth - 1;
824 thumb.bottom += PointDepth;
825 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
827 /* shadowed edge */
828 thumb.left += PointDepth;
829 thumb.right += PointDepth;
830 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
837 static inline void
838 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
840 TTTOOLINFOW ti;
842 if (!infoPtr->hwndToolTip) return;
844 ZeroMemory(&ti, sizeof(ti));
845 ti.cbSize = sizeof(ti);
846 ti.hwnd = infoPtr->hwndSelf;
848 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
852 static void
853 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
855 WCHAR buf[80];
856 TTTOOLINFOW ti;
857 POINT pt;
858 RECT rcClient;
859 LRESULT size;
861 if (!infoPtr->hwndToolTip) return;
863 ZeroMemory(&ti, sizeof(ti));
864 ti.cbSize = sizeof(ti);
865 ti.hwnd = infoPtr->hwndSelf;
866 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
868 wsprintfW (buf, L"%ld", infoPtr->lPos);
869 ti.lpszText = buf;
870 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
872 GetClientRect (infoPtr->hwndSelf, &rcClient);
873 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
874 if (infoPtr->dwStyle & TBS_VERT) {
875 if (infoPtr->fLocation == TBTS_LEFT)
876 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
877 else
878 pt.x = rcClient.right + TOOLTIP_OFFSET;
879 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
880 } else {
881 if (infoPtr->fLocation == TBTS_TOP)
882 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
883 else
884 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
885 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
887 ClientToScreen(infoPtr->hwndSelf, &pt);
889 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
890 0, MAKELPARAM(pt.x, pt.y));
894 static void
895 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
897 RECT rcClient;
898 HDC hdc;
899 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
900 NMCUSTOMDRAW nmcd;
901 int gcdrf, icdrf;
903 if (infoPtr->flags & TB_THUMBCHANGED) {
904 TRACKBAR_UpdateThumb (infoPtr);
905 if (infoPtr->flags & TB_THUMBSIZECHANGED)
906 TRACKBAR_CalcChannel (infoPtr);
908 if (infoPtr->flags & TB_SELECTIONCHANGED)
909 TRACKBAR_CalcSelection (infoPtr);
911 if (infoPtr->flags & TB_DRAG_MODE)
912 TRACKBAR_UpdateToolTip (infoPtr);
914 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
916 GetClientRect (infoPtr->hwndSelf, &rcClient);
918 /* try to render offscreen, if we fail, carrry onscreen */
919 hdc = CreateCompatibleDC(hdcDst);
920 if (hdc) {
921 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
922 if (hOffScreenBmp) {
923 hOldBmp = SelectObject(hdc, hOffScreenBmp);
924 } else {
925 DeleteObject(hdc);
926 hdc = hdcDst;
928 } else {
929 hdc = hdcDst;
932 ZeroMemory(&nmcd, sizeof(nmcd));
933 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
934 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
935 nmcd.hdr.code = NM_CUSTOMDRAW;
936 nmcd.hdc = hdc;
938 /* start the paint cycle */
939 nmcd.rc = rcClient;
940 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
941 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
943 /* Erase background */
944 if (gcdrf == CDRF_DODEFAULT ||
945 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
946 if (GetWindowTheme (infoPtr->hwndSelf)) {
947 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
949 else {
950 HBRUSH brush = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLORSTATIC,
951 (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
952 FillRect (hdc, &rcClient, brush ? brush : GetSysColorBrush(COLOR_BTNFACE));
954 if (gcdrf != CDRF_DODEFAULT)
955 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
958 /* draw channel */
959 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
960 nmcd.dwItemSpec = TBCD_CHANNEL;
961 nmcd.uItemState = CDIS_DEFAULT;
962 nmcd.rc = infoPtr->rcChannel;
963 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
964 } else icdrf = CDRF_DODEFAULT;
965 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
966 TRACKBAR_DrawChannel (infoPtr, hdc);
967 if (icdrf & CDRF_NOTIFYPOSTPAINT)
968 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
972 /* draw tics */
973 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
974 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
975 nmcd.dwItemSpec = TBCD_TICS;
976 nmcd.uItemState = CDIS_DEFAULT;
977 nmcd.rc = rcClient;
978 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
979 } else icdrf = CDRF_DODEFAULT;
980 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
981 TRACKBAR_DrawTics (infoPtr, hdc);
982 if (icdrf & CDRF_NOTIFYPOSTPAINT)
983 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
987 /* draw thumb */
988 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
989 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
990 nmcd.dwItemSpec = TBCD_THUMB;
991 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
992 nmcd.rc = infoPtr->rcThumb;
993 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
994 } else icdrf = CDRF_DODEFAULT;
995 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
996 TRACKBAR_DrawThumb(infoPtr, hdc);
997 if (icdrf & CDRF_NOTIFYPOSTPAINT)
998 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
1002 /* draw focus rectangle */
1003 if (infoPtr->flags & TB_IS_FOCUSED) {
1004 DrawFocusRect(hdc, &rcClient);
1007 /* finish up the painting */
1008 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
1009 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
1011 cleanup:
1012 /* cleanup, if we rendered offscreen */
1013 if (hdc != hdcDst) {
1014 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
1015 SelectObject(hdc, hOldBmp);
1016 DeleteObject(hOffScreenBmp);
1017 DeleteObject(hdc);
1022 static void
1023 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
1025 HWND hwndParent = GetParent (infoPtr->hwndSelf);
1026 RECT rcSelf, rcBuddy;
1027 INT x, y;
1029 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
1030 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
1032 /* align buddy left or above */
1033 if (infoPtr->hwndBuddyLA) {
1034 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
1035 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1037 if (infoPtr->dwStyle & TBS_VERT) {
1038 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1039 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1040 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
1042 else {
1043 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
1044 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1045 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1048 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
1049 SWP_NOZORDER | SWP_NOSIZE);
1053 /* align buddy right or below */
1054 if (infoPtr->hwndBuddyRB) {
1055 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
1056 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1058 if (infoPtr->dwStyle & TBS_VERT) {
1059 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1060 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1061 y = rcSelf.bottom;
1063 else {
1064 x = rcSelf.right;
1065 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1066 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1068 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
1069 SWP_NOZORDER | SWP_NOSIZE);
1074 static LRESULT
1075 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1077 infoPtr->lSelMin = 0;
1078 infoPtr->lSelMax = 0;
1079 infoPtr->flags |= TB_SELECTIONCHANGED;
1081 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1083 return 0;
1087 static LRESULT
1088 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1090 if (infoPtr->tics) {
1091 Free (infoPtr->tics);
1092 infoPtr->tics = NULL;
1093 infoPtr->uNumTics = 0;
1096 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1098 return 0;
1102 static inline LRESULT
1103 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1105 if (lprc == NULL) return 0;
1107 lprc->left = infoPtr->rcChannel.left;
1108 lprc->right = infoPtr->rcChannel.right;
1109 lprc->bottom = infoPtr->rcChannel.bottom;
1110 lprc->top = infoPtr->rcChannel.top;
1112 return 0;
1116 static inline LONG
1117 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1119 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1121 return infoPtr->uNumTics + 2;
1125 static int __cdecl comp_tics (const void *ap, const void *bp)
1127 const DWORD a = *(const DWORD *)ap;
1128 const DWORD b = *(const DWORD *)bp;
1130 TRACE("(a=%d, b=%d)\n", a, b);
1131 if (a < b) return -1;
1132 if (a > b) return 1;
1133 return 0;
1137 static inline LONG
1138 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1140 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1141 return -1;
1143 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1144 return infoPtr->tics[iTic];
1148 static inline LONG
1149 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1151 LONG range, width, pos, tic;
1152 int offsetthumb;
1154 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1155 return -1;
1157 tic = TRACKBAR_GetTic (infoPtr, iTic);
1158 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1159 if (range <= 0) range = 1;
1160 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1161 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1162 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1164 return pos;
1168 static HWND
1169 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1171 HWND hwndTemp;
1173 if (fLocation) {
1174 /* buddy is left or above */
1175 hwndTemp = infoPtr->hwndBuddyLA;
1176 infoPtr->hwndBuddyLA = hwndBuddy;
1178 else {
1179 /* buddy is right or below */
1180 hwndTemp = infoPtr->hwndBuddyRB;
1181 infoPtr->hwndBuddyRB = hwndBuddy;
1184 TRACKBAR_AlignBuddies (infoPtr);
1186 return hwndTemp;
1190 static inline LONG
1191 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1193 LONG lTemp = infoPtr->lLineSize;
1195 infoPtr->lLineSize = lLineSize;
1197 return lTemp;
1200 static void TRACKBAR_UpdatePageSize(TRACKBAR_INFO *infoPtr)
1202 if (infoPtr->flags & TB_USER_PAGE)
1203 return;
1205 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1206 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1209 static inline LONG
1210 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1212 LONG lTemp = infoPtr->lPageSize;
1214 if (lPageSize == -1)
1216 infoPtr->flags &= ~TB_USER_PAGE;
1217 TRACKBAR_UpdatePageSize(infoPtr);
1219 else
1221 infoPtr->flags |= TB_USER_PAGE;
1222 infoPtr->lPageSize = lPageSize;
1225 return lTemp;
1229 static inline LRESULT
1230 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1232 LONG oldPos = infoPtr->lPos;
1233 infoPtr->lPos = lPosition;
1235 if (infoPtr->lPos < infoPtr->lRangeMin)
1236 infoPtr->lPos = infoPtr->lRangeMin;
1238 if (infoPtr->lPos > infoPtr->lRangeMax)
1239 infoPtr->lPos = infoPtr->lRangeMax;
1241 if (fPosition && oldPos != lPosition)
1243 TRACKBAR_UpdateThumb(infoPtr);
1244 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1247 return 0;
1250 static inline LRESULT
1251 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
1253 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1254 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1256 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1257 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1259 /* clip position to new min/max limit */
1260 if (infoPtr->lPos < infoPtr->lRangeMin)
1261 infoPtr->lPos = infoPtr->lRangeMin;
1263 if (infoPtr->lPos > infoPtr->lRangeMax)
1264 infoPtr->lPos = infoPtr->lRangeMax;
1266 TRACKBAR_UpdatePageSize(infoPtr);
1268 if (changed) {
1269 if (infoPtr->dwStyle & TBS_AUTOTICKS)
1270 TRACKBAR_RecalculateTics (infoPtr);
1271 infoPtr->flags |= TB_THUMBPOSCHANGED;
1274 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1276 return 0;
1280 static inline LRESULT
1281 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1283 BOOL changed = infoPtr->lRangeMax != lMax;
1284 LONG rightmost = max(lMax, infoPtr->lRangeMin);
1286 infoPtr->lRangeMax = lMax;
1287 if (infoPtr->lPos > rightmost) {
1288 infoPtr->lPos = rightmost;
1289 infoPtr->flags |= TB_THUMBPOSCHANGED;
1292 TRACKBAR_UpdatePageSize(infoPtr);
1294 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1295 TRACKBAR_RecalculateTics (infoPtr);
1297 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1299 return 0;
1303 static inline LRESULT
1304 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1306 BOOL changed = infoPtr->lRangeMin != lMin;
1308 infoPtr->lRangeMin = lMin;
1309 if (infoPtr->lPos < infoPtr->lRangeMin) {
1310 infoPtr->lPos = infoPtr->lRangeMin;
1311 infoPtr->flags |= TB_THUMBPOSCHANGED;
1314 TRACKBAR_UpdatePageSize(infoPtr);
1316 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1317 TRACKBAR_RecalculateTics (infoPtr);
1319 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1321 return 0;
1325 static inline LRESULT
1326 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1328 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1329 infoPtr->lSelMin = 0;
1330 infoPtr->lSelMax = 0;
1331 return 0;
1334 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1335 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1336 infoPtr->flags |= TB_SELECTIONCHANGED;
1338 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1339 infoPtr->lSelMin = infoPtr->lRangeMin;
1340 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1341 infoPtr->lSelMax = infoPtr->lRangeMax;
1343 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1345 return 0;
1349 static inline LRESULT
1350 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1352 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1353 infoPtr->lSelMax = 0;
1354 return 0;
1357 infoPtr->lSelMax = lEnd;
1358 infoPtr->flags |= TB_SELECTIONCHANGED;
1360 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1361 infoPtr->lSelMax = infoPtr->lRangeMax;
1363 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1365 return 0;
1369 static inline LRESULT
1370 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1372 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1373 infoPtr->lSelMin = 0;
1374 return 0;
1377 infoPtr->lSelMin = lStart;
1378 infoPtr->flags |=TB_SELECTIONCHANGED;
1380 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1381 infoPtr->lSelMin = infoPtr->lRangeMin;
1383 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1385 return 0;
1389 static inline LRESULT
1390 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1392 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1393 /* We're not supposed to check if it's really changed or not,
1394 just repaint in any case. */
1395 infoPtr->uThumbLen = iLength;
1396 infoPtr->flags |= TB_THUMBSIZECHANGED;
1397 TRACKBAR_InvalidateAll(infoPtr);
1400 return 0;
1404 static inline LRESULT
1405 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1407 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1408 return FALSE;
1410 TRACE("lPos=%d\n", lPos);
1412 infoPtr->uNumTics++;
1413 infoPtr->tics=ReAlloc( infoPtr->tics,
1414 (infoPtr->uNumTics)*sizeof (DWORD));
1415 if (!infoPtr->tics) {
1416 infoPtr->uNumTics = 0;
1417 notify(infoPtr, NM_OUTOFMEMORY);
1418 return FALSE;
1420 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1422 TRACKBAR_InvalidateAll(infoPtr);
1424 return TRUE;
1428 static inline LRESULT
1429 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1431 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1432 infoPtr->uTicFreq = wFreq;
1433 TRACKBAR_RecalculateTics (infoPtr);
1434 TRACKBAR_InvalidateAll(infoPtr);
1437 TRACKBAR_UpdateThumb (infoPtr);
1438 return 0;
1442 static inline INT
1443 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1445 INT fTemp = infoPtr->fLocation;
1447 infoPtr->fLocation = fLocation;
1449 return fTemp;
1453 static inline LRESULT
1454 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1456 infoPtr->hwndToolTip = hwndTT;
1458 return 0;
1462 static inline BOOL
1463 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1465 BOOL bTemp = infoPtr->bUnicode;
1467 infoPtr->bUnicode = fUnicode;
1469 return bTemp;
1472 static int get_scaled_metric(const TRACKBAR_INFO *infoPtr, int value)
1474 return MulDiv(value, GetDpiForWindow(infoPtr->hwndSelf), 96);
1477 static LRESULT
1478 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1480 int client_size;
1481 RECT rect;
1483 infoPtr->uThumbLen = get_scaled_metric(infoPtr, infoPtr->dwStyle & TBS_ENABLESELRANGE ? 23 : 21);
1485 if (!(infoPtr->dwStyle & TBS_FIXEDLENGTH))
1487 GetClientRect(infoPtr->hwndSelf, &rect);
1488 if (infoPtr->dwStyle & TBS_VERT)
1489 client_size = rect.right - rect.left;
1490 else
1491 client_size = rect.bottom - rect.top;
1493 if (client_size < infoPtr->uThumbLen)
1494 infoPtr->uThumbLen = client_size > get_scaled_metric(infoPtr, 9) ?
1495 client_size - get_scaled_metric(infoPtr, 5) : get_scaled_metric(infoPtr, 4);
1498 TRACKBAR_CalcChannel (infoPtr);
1499 TRACKBAR_UpdateThumb (infoPtr);
1500 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1502 return 0;
1505 static void TRACKBAR_RecalculateAll (TRACKBAR_INFO *infoPtr)
1507 if (infoPtr->dwStyle & TBS_FIXEDLENGTH)
1509 TRACKBAR_CalcChannel(infoPtr);
1510 TRACKBAR_UpdateThumb(infoPtr);
1512 else
1514 TRACKBAR_InitializeThumb(infoPtr);
1516 TRACKBAR_AlignBuddies(infoPtr);
1519 static LRESULT
1520 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1522 TRACKBAR_INFO *infoPtr;
1524 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1525 if (!infoPtr) return -1;
1526 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1528 /* set default values */
1529 infoPtr->hwndSelf = hwnd;
1530 infoPtr->dwStyle = lpcs->style;
1531 infoPtr->lRangeMin = 0;
1532 infoPtr->lRangeMax = 100;
1533 infoPtr->lLineSize = 1;
1534 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1535 infoPtr->lSelMin = 0;
1536 infoPtr->lSelMax = 0;
1537 infoPtr->lPos = 0;
1538 infoPtr->fLocation = TBTS_TOP;
1539 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1540 infoPtr->uTicFreq = 1;
1541 infoPtr->tics = NULL;
1542 infoPtr->hwndNotify= lpcs->hwndParent;
1544 TRACKBAR_InitializeThumb (infoPtr);
1546 /* Create tooltip control */
1547 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1549 infoPtr->hwndToolTip =
1550 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1551 CW_USEDEFAULT, CW_USEDEFAULT,
1552 CW_USEDEFAULT, CW_USEDEFAULT,
1553 hwnd, 0, 0, 0);
1555 if (infoPtr->hwndToolTip) {
1556 TTTOOLINFOW ti;
1557 WCHAR wEmpty[] = L"";
1558 ZeroMemory (&ti, sizeof(ti));
1559 ti.cbSize = sizeof(ti);
1560 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1561 ti.hwnd = hwnd;
1562 ti.lpszText = wEmpty;
1564 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1568 OpenThemeData (hwnd, themeClass);
1570 return 0;
1574 static LRESULT
1575 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1577 /* delete tooltip control */
1578 if (infoPtr->hwndToolTip)
1579 DestroyWindow (infoPtr->hwndToolTip);
1581 Free (infoPtr->tics);
1582 infoPtr->tics = NULL;
1584 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1585 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1586 Free (infoPtr);
1588 return 0;
1592 static LRESULT
1593 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1595 TRACE("\n");
1596 infoPtr->flags &= ~TB_IS_FOCUSED;
1597 TRACKBAR_InvalidateAll(infoPtr);
1599 return 0;
1602 static LRESULT
1603 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1605 POINT clickPoint;
1607 clickPoint.x = x;
1608 clickPoint.y = y;
1610 SetFocus(infoPtr->hwndSelf);
1612 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1613 infoPtr->flags |= TB_DRAG_MODE;
1614 SetCapture (infoPtr->hwndSelf);
1615 TRACKBAR_UpdateToolTip (infoPtr);
1616 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1617 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1618 } else {
1619 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1620 if (dir == 0) return 0;
1621 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1622 TRACKBAR_AutoPage (infoPtr, clickPoint);
1623 SetCapture (infoPtr->hwndSelf);
1624 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1627 return 0;
1631 static LRESULT
1632 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1634 if (infoPtr->flags & TB_DRAG_MODE) {
1635 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1636 notify_with_scroll (infoPtr, TB_ENDTRACK);
1637 infoPtr->flags &= ~TB_DRAG_MODE;
1638 ReleaseCapture ();
1639 notify(infoPtr, NM_RELEASEDCAPTURE);
1640 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1641 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1643 if (infoPtr->flags & TB_AUTO_PAGE) {
1644 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1645 infoPtr->flags &= ~TB_AUTO_PAGE;
1646 notify_with_scroll (infoPtr, TB_ENDTRACK);
1647 ReleaseCapture ();
1648 notify(infoPtr, NM_RELEASEDCAPTURE);
1651 return 0;
1655 static LRESULT
1656 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1658 notify_with_scroll (infoPtr, TB_ENDTRACK);
1659 return 0;
1663 static LRESULT
1664 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1666 if (hdc) {
1667 TRACKBAR_Refresh(infoPtr, hdc);
1668 } else {
1669 PAINTSTRUCT ps;
1670 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1671 TRACKBAR_Refresh (infoPtr, hdc);
1672 EndPaint (infoPtr->hwndSelf, &ps);
1675 return 0;
1679 static LRESULT
1680 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1682 TRACE("\n");
1683 infoPtr->flags |= TB_IS_FOCUSED;
1684 TRACKBAR_InvalidateAll(infoPtr);
1686 return 0;
1690 static LRESULT
1691 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1693 TRACKBAR_RecalculateAll(infoPtr);
1694 TRACKBAR_InvalidateAll(infoPtr);
1696 return 0;
1699 static LRESULT
1700 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1701 const STYLESTRUCT *lpss)
1703 if (wStyleType != GWL_STYLE) return 0;
1705 infoPtr->dwStyle = lpss->styleNew;
1706 TRACKBAR_RecalculateAll(infoPtr);
1707 TRACKBAR_InvalidateAll(infoPtr);
1708 return 0;
1711 static LRESULT
1712 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1714 if (infoPtr->flags & TB_AUTO_PAGE) {
1715 POINT pt;
1716 if (GetCursorPos(&pt))
1717 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1718 TRACKBAR_AutoPage(infoPtr, pt);
1720 return 0;
1724 /* update theme after a WM_THEMECHANGED message */
1725 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1727 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1728 CloseThemeData (theme);
1729 OpenThemeData (infoPtr->hwndSelf, themeClass);
1730 InvalidateRect (infoPtr->hwndSelf, NULL, FALSE);
1731 return 0;
1735 static LRESULT
1736 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1738 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1739 LONG dragPos, oldPos = infoPtr->lPos;
1741 TRACE("(x=%d. y=%d)\n", x, y);
1743 if (infoPtr->flags & TB_AUTO_PAGE) {
1744 POINT pt;
1745 pt.x = x;
1746 pt.y = y;
1747 TRACKBAR_AutoPage (infoPtr, pt);
1748 return TRUE;
1751 if (!(infoPtr->flags & TB_DRAG_MODE))
1753 if (GetWindowTheme (infoPtr->hwndSelf))
1755 DWORD oldFlags = infoPtr->flags;
1756 POINT pt;
1757 pt.x = x;
1758 pt.y = y;
1759 if (PtInRect (&infoPtr->rcThumb, pt))
1761 TRACKMOUSEEVENT tme;
1762 tme.cbSize = sizeof( tme );
1763 tme.dwFlags = TME_LEAVE;
1764 tme.hwndTrack = infoPtr->hwndSelf;
1765 TrackMouseEvent( &tme );
1766 infoPtr->flags |= TB_THUMB_HOT;
1768 else
1770 TRACKMOUSEEVENT tme;
1771 tme.cbSize = sizeof( tme );
1772 tme.dwFlags = TME_CANCEL;
1773 tme.hwndTrack = infoPtr->hwndSelf;
1774 TrackMouseEvent( &tme );
1775 infoPtr->flags &= ~TB_THUMB_HOT;
1777 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1779 return TRUE;
1782 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1784 if (dragPos == oldPos) return TRUE;
1786 infoPtr->lPos = dragPos;
1787 TRACKBAR_UpdateThumb (infoPtr);
1789 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1791 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1792 UpdateWindow (infoPtr->hwndSelf);
1794 return TRUE;
1797 static BOOL
1798 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1800 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1801 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1802 LONG pos = infoPtr->lPos;
1804 TRACE("%x\n", nVirtKey);
1806 switch (nVirtKey) {
1807 case VK_UP:
1808 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1809 else TRACKBAR_LineUp(infoPtr);
1810 break;
1811 case VK_LEFT:
1812 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1813 else TRACKBAR_LineUp(infoPtr);
1814 break;
1815 case VK_DOWN:
1816 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1817 else TRACKBAR_LineDown(infoPtr);
1818 break;
1819 case VK_RIGHT:
1820 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1821 else TRACKBAR_LineDown(infoPtr);
1822 break;
1823 case VK_NEXT:
1824 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1825 else TRACKBAR_PageDown(infoPtr);
1826 break;
1827 case VK_PRIOR:
1828 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1829 else TRACKBAR_PageUp(infoPtr);
1830 break;
1831 case VK_HOME:
1832 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1833 infoPtr->lPos = infoPtr->lRangeMin;
1834 notify_with_scroll (infoPtr, TB_TOP);
1835 break;
1836 case VK_END:
1837 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1838 infoPtr->lPos = infoPtr->lRangeMax;
1839 notify_with_scroll (infoPtr, TB_BOTTOM);
1840 break;
1843 if (pos != infoPtr->lPos) {
1844 TRACKBAR_UpdateThumb (infoPtr);
1845 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1848 return TRUE;
1852 static inline BOOL
1853 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1855 switch (nVirtKey) {
1856 case VK_LEFT:
1857 case VK_UP:
1858 case VK_RIGHT:
1859 case VK_DOWN:
1860 case VK_NEXT:
1861 case VK_PRIOR:
1862 case VK_HOME:
1863 case VK_END:
1864 notify_with_scroll (infoPtr, TB_ENDTRACK);
1866 return TRUE;
1870 static LRESULT
1871 TRACKBAR_Enable (TRACKBAR_INFO *infoPtr, BOOL enable)
1873 if (enable)
1874 infoPtr->dwStyle &= ~WS_DISABLED;
1875 else
1876 infoPtr->dwStyle |= WS_DISABLED;
1878 InvalidateRect(infoPtr->hwndSelf, &infoPtr->rcThumb, TRUE);
1880 return 1;
1883 static LRESULT WINAPI
1884 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1886 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1888 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1890 if (!infoPtr && (uMsg != WM_CREATE))
1891 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1893 switch (uMsg)
1895 case TBM_CLEARSEL:
1896 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1898 case TBM_CLEARTICS:
1899 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1901 case TBM_GETBUDDY:
1902 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1904 case TBM_GETCHANNELRECT:
1905 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1907 case TBM_GETLINESIZE:
1908 return infoPtr->lLineSize;
1910 case TBM_GETNUMTICS:
1911 return TRACKBAR_GetNumTics (infoPtr);
1913 case TBM_GETPAGESIZE:
1914 return infoPtr->lPageSize;
1916 case TBM_GETPOS:
1917 return infoPtr->lPos;
1919 case TBM_GETPTICS:
1920 return (LRESULT)infoPtr->tics;
1922 case TBM_GETRANGEMAX:
1923 return infoPtr->lRangeMax;
1925 case TBM_GETRANGEMIN:
1926 return infoPtr->lRangeMin;
1928 case TBM_GETSELEND:
1929 return infoPtr->lSelMax;
1931 case TBM_GETSELSTART:
1932 return infoPtr->lSelMin;
1934 case TBM_GETTHUMBLENGTH:
1935 return infoPtr->uThumbLen;
1937 case TBM_GETTHUMBRECT:
1938 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1940 case TBM_GETTIC:
1941 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1943 case TBM_GETTICPOS:
1944 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1946 case TBM_GETTOOLTIPS:
1947 return (LRESULT)infoPtr->hwndToolTip;
1949 case TBM_GETUNICODEFORMAT:
1950 return infoPtr->bUnicode;
1952 case TBM_SETBUDDY:
1953 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1955 case TBM_SETLINESIZE:
1956 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1958 case TBM_SETPAGESIZE:
1959 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1961 case TBM_SETPOS:
1962 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1964 case TBM_SETRANGE:
1965 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1967 case TBM_SETRANGEMAX:
1968 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1970 case TBM_SETRANGEMIN:
1971 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1973 case TBM_SETSEL:
1974 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1976 case TBM_SETSELEND:
1977 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1979 case TBM_SETSELSTART:
1980 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1982 case TBM_SETTHUMBLENGTH:
1983 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1985 case TBM_SETTIC:
1986 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1988 case TBM_SETTICFREQ:
1989 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1991 case TBM_SETTIPSIDE:
1992 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1994 case TBM_SETTOOLTIPS:
1995 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1997 case TBM_SETUNICODEFORMAT:
1998 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
2001 case WM_CAPTURECHANGED:
2002 if (hwnd == (HWND)lParam) return 0;
2003 return TRACKBAR_CaptureChanged (infoPtr);
2005 case WM_CREATE:
2006 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
2008 case WM_DESTROY:
2009 return TRACKBAR_Destroy (infoPtr);
2011 case WM_ENABLE:
2012 return TRACKBAR_Enable (infoPtr, (BOOL)wParam);
2014 case WM_ERASEBKGND:
2015 return 0;
2017 case WM_GETDLGCODE:
2018 return DLGC_WANTARROWS;
2020 case WM_KEYDOWN:
2021 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
2023 case WM_KEYUP:
2024 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
2026 case WM_KILLFOCUS:
2027 return TRACKBAR_KillFocus (infoPtr);
2029 case WM_LBUTTONDOWN:
2030 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2032 case WM_LBUTTONUP:
2033 return TRACKBAR_LButtonUp (infoPtr);
2035 case WM_MOUSELEAVE:
2036 infoPtr->flags &= ~TB_THUMB_HOT;
2037 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
2038 return 0;
2040 case WM_MOUSEMOVE:
2041 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2043 case WM_PRINTCLIENT:
2044 case WM_PAINT:
2045 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
2047 case WM_SETFOCUS:
2048 return TRACKBAR_SetFocus (infoPtr);
2050 case WM_SIZE:
2051 return TRACKBAR_Size (infoPtr);
2053 case WM_STYLECHANGED:
2054 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2056 case WM_THEMECHANGED:
2057 return theme_changed (infoPtr);
2059 case WM_TIMER:
2060 return TRACKBAR_Timer (infoPtr);
2062 case WM_WININICHANGE:
2063 return TRACKBAR_InitializeThumb (infoPtr);
2065 default:
2066 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2067 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2068 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2073 void TRACKBAR_Register (void)
2075 WNDCLASSW wndClass;
2077 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2078 wndClass.style = CS_GLOBALCLASS;
2079 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
2080 wndClass.cbClsExtra = 0;
2081 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
2082 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2083 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2084 wndClass.lpszClassName = TRACKBAR_CLASSW;
2086 RegisterClassW (&wndClass);
2090 void TRACKBAR_Unregister (void)
2092 UnregisterClassW (TRACKBAR_CLASSW, NULL);