user32/tests: Avoid side-effect in an assert.
[wine.git] / dlls / comctl32 / trackbar.c
blob6d092a306cbc2e8a07b8f5a6a9ace2547b3440ec
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;
503 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb - 1;
504 } else {
505 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
506 rcTics.left = infoPtr->rcChannel.left + offsetthumb;
507 rcTics.right = infoPtr->rcChannel.right - offsetthumb - 1;
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 int
616 TRACKBAR_FillThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, HBRUSH hbrush)
618 const RECT *thumb = &infoPtr->rcThumb;
619 POINT points[6];
620 int PointDepth;
621 HBRUSH oldbr;
623 if (infoPtr->dwStyle & TBS_BOTH)
625 FillRect(hdc, thumb, hbrush);
626 return 0;
629 if (infoPtr->dwStyle & TBS_VERT)
631 PointDepth = (thumb->bottom - thumb->top) / 2;
632 if (infoPtr->dwStyle & TBS_LEFT)
634 points[0].x = thumb->right-1;
635 points[0].y = thumb->top;
636 points[1].x = thumb->right-1;
637 points[1].y = thumb->bottom-1;
638 points[2].x = thumb->left + PointDepth;
639 points[2].y = thumb->bottom-1;
640 points[3].x = thumb->left;
641 points[3].y = thumb->top + PointDepth;
642 points[4].x = thumb->left + PointDepth;
643 points[4].y = thumb->top;
644 points[5].x = points[0].x;
645 points[5].y = points[0].y;
647 else
649 points[0].x = thumb->right;
650 points[0].y = thumb->top + PointDepth;
651 points[1].x = thumb->right - PointDepth;
652 points[1].y = thumb->bottom-1;
653 points[2].x = thumb->left;
654 points[2].y = thumb->bottom-1;
655 points[3].x = thumb->left;
656 points[3].y = thumb->top;
657 points[4].x = thumb->right - PointDepth;
658 points[4].y = thumb->top;
659 points[5].x = points[0].x;
660 points[5].y = points[0].y;
663 else
665 PointDepth = (thumb->right - thumb->left) / 2;
666 if (infoPtr->dwStyle & TBS_TOP)
668 points[0].x = thumb->left + PointDepth;
669 points[0].y = thumb->top+1;
670 points[1].x = thumb->right-1;
671 points[1].y = thumb->top + PointDepth + 1;
672 points[2].x = thumb->right-1;
673 points[2].y = thumb->bottom-1;
674 points[3].x = thumb->left;
675 points[3].y = thumb->bottom-1;
676 points[4].x = thumb->left;
677 points[4].y = thumb->top + PointDepth + 1;
678 points[5].x = points[0].x;
679 points[5].y = points[0].y;
681 else
683 points[0].x = thumb->right-1;
684 points[0].y = thumb->top;
685 points[1].x = thumb->right-1;
686 points[1].y = thumb->bottom - PointDepth - 1;
687 points[2].x = thumb->left + PointDepth;
688 points[2].y = thumb->bottom-1;
689 points[3].x = thumb->left;
690 points[3].y = thumb->bottom - PointDepth - 1;
691 points[4].x = thumb->left;
692 points[4].y = thumb->top;
693 points[5].x = points[0].x;
694 points[5].y = points[0].y;
698 oldbr = SelectObject(hdc, hbrush);
699 SetPolyFillMode(hdc, WINDING);
700 Polygon(hdc, points, sizeof(points) / sizeof(points[0]));
701 SelectObject(hdc, oldbr);
703 return PointDepth;
706 static void
707 TRACKBAR_DrawThumb (TRACKBAR_INFO *infoPtr, HDC hdc)
709 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
710 int PointDepth;
711 HBRUSH brush;
713 if (theme)
715 int partId;
716 int stateId;
717 if (infoPtr->dwStyle & TBS_BOTH)
718 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
719 else if (infoPtr->dwStyle & TBS_LEFT)
720 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
721 else
722 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
724 if (infoPtr->dwStyle & WS_DISABLED)
725 stateId = TUS_DISABLED;
726 else if (infoPtr->flags & TB_DRAG_MODE)
727 stateId = TUS_PRESSED;
728 else if (infoPtr->flags & TB_THUMB_HOT)
729 stateId = TUS_HOT;
730 else
731 stateId = TUS_NORMAL;
733 DrawThemeBackground (theme, hdc, partId, stateId, &infoPtr->rcThumb, NULL);
735 return;
738 if (infoPtr->dwStyle & WS_DISABLED || infoPtr->flags & TB_DRAG_MODE)
740 if (comctl32_color.clr3dHilight == comctl32_color.clrWindow)
741 brush = COMCTL32_hPattern55AABrush;
742 else
743 brush = GetSysColorBrush(COLOR_SCROLLBAR);
745 SetTextColor(hdc, comctl32_color.clr3dFace);
746 SetBkColor(hdc, comctl32_color.clr3dHilight);
748 else
749 brush = GetSysColorBrush(COLOR_BTNFACE);
751 PointDepth = TRACKBAR_FillThumb(infoPtr, hdc, brush);
753 if (infoPtr->dwStyle & TBS_BOTH)
755 DrawEdge(hdc, &infoPtr->rcThumb, EDGE_RAISED, BF_RECT | BF_SOFT);
756 return;
758 else
760 RECT thumb = infoPtr->rcThumb;
762 if (infoPtr->dwStyle & TBS_VERT)
764 if (infoPtr->dwStyle & TBS_LEFT)
766 /* rectangular part */
767 thumb.left += PointDepth;
768 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_RIGHT | BF_BOTTOM | BF_SOFT);
770 /* light edge */
771 thumb.left -= PointDepth;
772 thumb.right = thumb.left + PointDepth;
773 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
774 thumb.top = infoPtr->rcThumb.top;
775 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
777 /* shadowed edge */
778 thumb.top += PointDepth;
779 thumb.bottom += PointDepth;
780 DrawEdge(hdc, &thumb, EDGE_SUNKEN, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
781 return;
783 else
785 /* rectangular part */
786 thumb.right -= PointDepth;
787 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_LEFT | BF_BOTTOM | BF_SOFT);
789 /* light edge */
790 thumb.left = thumb.right;
791 thumb.right += PointDepth + 1;
792 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
793 thumb.top = infoPtr->rcThumb.top;
794 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
796 /* shadowed edge */
797 thumb.top += PointDepth;
798 thumb.bottom += PointDepth;
799 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
802 else
804 if (infoPtr->dwStyle & TBS_TOP)
806 /* rectangular part */
807 thumb.top += PointDepth;
808 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_BOTTOM | BF_RIGHT | BF_SOFT);
810 /* light edge */
811 thumb.left = infoPtr->rcThumb.left;
812 thumb.right = thumb.left + PointDepth;
813 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
814 thumb.top -= PointDepth;
815 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
817 /* shadowed edge */
818 thumb.left += PointDepth;
819 thumb.right += PointDepth;
820 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMRIGHT | BF_SOFT);
822 else
824 /* rectangular part */
825 thumb.bottom -= PointDepth;
826 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT);
828 /* light edge */
829 thumb.left = infoPtr->rcThumb.left;
830 thumb.right = thumb.left + PointDepth;
831 thumb.top = infoPtr->rcThumb.bottom - PointDepth - 1;
832 thumb.bottom += PointDepth;
833 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
835 /* shadowed edge */
836 thumb.left += PointDepth;
837 thumb.right += PointDepth;
838 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
845 static inline void
846 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
848 TTTOOLINFOW ti;
850 if (!infoPtr->hwndToolTip) return;
852 ZeroMemory(&ti, sizeof(ti));
853 ti.cbSize = sizeof(ti);
854 ti.hwnd = infoPtr->hwndSelf;
856 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
860 static void
861 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
863 WCHAR buf[80];
864 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
865 TTTOOLINFOW ti;
866 POINT pt;
867 RECT rcClient;
868 LRESULT size;
870 if (!infoPtr->hwndToolTip) return;
872 ZeroMemory(&ti, sizeof(ti));
873 ti.cbSize = sizeof(ti);
874 ti.hwnd = infoPtr->hwndSelf;
875 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
877 wsprintfW (buf, fmt, infoPtr->lPos);
878 ti.lpszText = buf;
879 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
881 GetClientRect (infoPtr->hwndSelf, &rcClient);
882 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
883 if (infoPtr->dwStyle & TBS_VERT) {
884 if (infoPtr->fLocation == TBTS_LEFT)
885 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
886 else
887 pt.x = rcClient.right + TOOLTIP_OFFSET;
888 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
889 } else {
890 if (infoPtr->fLocation == TBTS_TOP)
891 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
892 else
893 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
894 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
896 ClientToScreen(infoPtr->hwndSelf, &pt);
898 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
899 0, MAKELPARAM(pt.x, pt.y));
903 static void
904 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
906 RECT rcClient;
907 HDC hdc;
908 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
909 NMCUSTOMDRAW nmcd;
910 int gcdrf, icdrf;
912 if (infoPtr->flags & TB_THUMBCHANGED) {
913 TRACKBAR_UpdateThumb (infoPtr);
914 if (infoPtr->flags & TB_THUMBSIZECHANGED)
915 TRACKBAR_CalcChannel (infoPtr);
917 if (infoPtr->flags & TB_SELECTIONCHANGED)
918 TRACKBAR_CalcSelection (infoPtr);
920 if (infoPtr->flags & TB_DRAG_MODE)
921 TRACKBAR_UpdateToolTip (infoPtr);
923 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
925 GetClientRect (infoPtr->hwndSelf, &rcClient);
927 /* try to render offscreen, if we fail, carrry onscreen */
928 hdc = CreateCompatibleDC(hdcDst);
929 if (hdc) {
930 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
931 if (hOffScreenBmp) {
932 hOldBmp = SelectObject(hdc, hOffScreenBmp);
933 } else {
934 DeleteObject(hdc);
935 hdc = hdcDst;
937 } else {
938 hdc = hdcDst;
941 ZeroMemory(&nmcd, sizeof(nmcd));
942 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
943 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
944 nmcd.hdr.code = NM_CUSTOMDRAW;
945 nmcd.hdc = hdc;
947 /* start the paint cycle */
948 nmcd.rc = rcClient;
949 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
950 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
952 /* Erase background */
953 if (gcdrf == CDRF_DODEFAULT ||
954 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
955 if (GetWindowTheme (infoPtr->hwndSelf)) {
956 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
958 else
959 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
960 if (gcdrf != CDRF_DODEFAULT)
961 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
964 /* draw channel */
965 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
966 nmcd.dwItemSpec = TBCD_CHANNEL;
967 nmcd.uItemState = CDIS_DEFAULT;
968 nmcd.rc = infoPtr->rcChannel;
969 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
970 } else icdrf = CDRF_DODEFAULT;
971 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
972 TRACKBAR_DrawChannel (infoPtr, hdc);
973 if (icdrf & CDRF_NOTIFYPOSTPAINT)
974 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
978 /* draw tics */
979 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
980 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
981 nmcd.dwItemSpec = TBCD_TICS;
982 nmcd.uItemState = CDIS_DEFAULT;
983 nmcd.rc = rcClient;
984 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
985 } else icdrf = CDRF_DODEFAULT;
986 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
987 TRACKBAR_DrawTics (infoPtr, hdc);
988 if (icdrf & CDRF_NOTIFYPOSTPAINT)
989 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
993 /* draw thumb */
994 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
995 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
996 nmcd.dwItemSpec = TBCD_THUMB;
997 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
998 nmcd.rc = infoPtr->rcThumb;
999 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
1000 } else icdrf = CDRF_DODEFAULT;
1001 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
1002 TRACKBAR_DrawThumb(infoPtr, hdc);
1003 if (icdrf & CDRF_NOTIFYPOSTPAINT)
1004 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
1008 /* draw focus rectangle */
1009 if (infoPtr->bFocussed) {
1010 DrawFocusRect(hdc, &rcClient);
1013 /* finish up the painting */
1014 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
1015 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
1017 cleanup:
1018 /* cleanup, if we rendered offscreen */
1019 if (hdc != hdcDst) {
1020 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
1021 SelectObject(hdc, hOldBmp);
1022 DeleteObject(hOffScreenBmp);
1023 DeleteObject(hdc);
1028 static void
1029 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
1031 HWND hwndParent = GetParent (infoPtr->hwndSelf);
1032 RECT rcSelf, rcBuddy;
1033 INT x, y;
1035 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
1036 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
1038 /* align buddy left or above */
1039 if (infoPtr->hwndBuddyLA) {
1040 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
1041 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1043 if (infoPtr->dwStyle & TBS_VERT) {
1044 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1045 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1046 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
1048 else {
1049 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
1050 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1051 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1054 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
1055 SWP_NOZORDER | SWP_NOSIZE);
1059 /* align buddy right or below */
1060 if (infoPtr->hwndBuddyRB) {
1061 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
1062 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1064 if (infoPtr->dwStyle & TBS_VERT) {
1065 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1066 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1067 y = rcSelf.bottom;
1069 else {
1070 x = rcSelf.right;
1071 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1072 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1074 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
1075 SWP_NOZORDER | SWP_NOSIZE);
1080 static LRESULT
1081 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1083 infoPtr->lSelMin = 0;
1084 infoPtr->lSelMax = 0;
1085 infoPtr->flags |= TB_SELECTIONCHANGED;
1087 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1089 return 0;
1093 static LRESULT
1094 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1096 if (infoPtr->tics) {
1097 Free (infoPtr->tics);
1098 infoPtr->tics = NULL;
1099 infoPtr->uNumTics = 0;
1102 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1104 return 0;
1108 static inline LRESULT
1109 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1111 if (lprc == NULL) return 0;
1113 lprc->left = infoPtr->rcChannel.left;
1114 lprc->right = infoPtr->rcChannel.right;
1115 lprc->bottom = infoPtr->rcChannel.bottom;
1116 lprc->top = infoPtr->rcChannel.top;
1118 return 0;
1122 static inline LONG
1123 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1125 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1127 return infoPtr->uNumTics + 2;
1131 static int comp_tics (const void *ap, const void *bp)
1133 const DWORD a = *(const DWORD *)ap;
1134 const DWORD b = *(const DWORD *)bp;
1136 TRACE("(a=%d, b=%d)\n", a, b);
1137 if (a < b) return -1;
1138 if (a > b) return 1;
1139 return 0;
1143 static inline LONG
1144 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1146 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1147 return -1;
1149 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1150 return infoPtr->tics[iTic];
1154 static inline LONG
1155 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1157 LONG range, width, pos, tic;
1158 int offsetthumb;
1160 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1161 return -1;
1163 tic = TRACKBAR_GetTic (infoPtr, iTic);
1164 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1165 if (range <= 0) range = 1;
1166 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1167 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1168 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1170 return pos;
1174 static HWND
1175 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1177 HWND hwndTemp;
1179 if (fLocation) {
1180 /* buddy is left or above */
1181 hwndTemp = infoPtr->hwndBuddyLA;
1182 infoPtr->hwndBuddyLA = hwndBuddy;
1184 else {
1185 /* buddy is right or below */
1186 hwndTemp = infoPtr->hwndBuddyRB;
1187 infoPtr->hwndBuddyRB = hwndBuddy;
1190 TRACKBAR_AlignBuddies (infoPtr);
1192 return hwndTemp;
1196 static inline LONG
1197 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1199 LONG lTemp = infoPtr->lLineSize;
1201 infoPtr->lLineSize = lLineSize;
1203 return lTemp;
1207 static inline LONG
1208 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1210 LONG lTemp = infoPtr->lPageSize;
1212 if (lPageSize != -1)
1213 infoPtr->lPageSize = lPageSize;
1214 else
1215 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1217 return lTemp;
1221 static inline LRESULT
1222 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1224 LONG oldPos = infoPtr->lPos;
1225 infoPtr->lPos = lPosition;
1227 if (infoPtr->lPos < infoPtr->lRangeMin)
1228 infoPtr->lPos = infoPtr->lRangeMin;
1230 if (infoPtr->lPos > infoPtr->lRangeMax)
1231 infoPtr->lPos = infoPtr->lRangeMax;
1232 infoPtr->flags |= TB_THUMBPOSCHANGED;
1234 if (fPosition && oldPos != lPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1236 return 0;
1240 static inline LRESULT
1241 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
1243 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1244 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1246 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1247 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1249 if (infoPtr->lPos < infoPtr->lRangeMin) {
1250 infoPtr->lPos = infoPtr->lRangeMin;
1251 infoPtr->flags |= TB_THUMBPOSCHANGED;
1254 if (infoPtr->lPos > infoPtr->lRangeMax) {
1255 infoPtr->lPos = infoPtr->lRangeMax;
1256 infoPtr->flags |= TB_THUMBPOSCHANGED;
1259 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1260 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1262 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1263 TRACKBAR_RecalculateTics (infoPtr);
1265 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1267 return 0;
1271 static inline LRESULT
1272 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1274 BOOL changed = infoPtr->lRangeMax != lMax;
1276 infoPtr->lRangeMax = lMax;
1277 if (infoPtr->lPos > infoPtr->lRangeMax) {
1278 infoPtr->lPos = infoPtr->lRangeMax;
1279 infoPtr->flags |= TB_THUMBPOSCHANGED;
1282 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1283 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1285 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1286 TRACKBAR_RecalculateTics (infoPtr);
1288 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1290 return 0;
1294 static inline LRESULT
1295 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1297 BOOL changed = infoPtr->lRangeMin != lMin;
1299 infoPtr->lRangeMin = lMin;
1300 if (infoPtr->lPos < infoPtr->lRangeMin) {
1301 infoPtr->lPos = infoPtr->lRangeMin;
1302 infoPtr->flags |= TB_THUMBPOSCHANGED;
1305 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1306 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1308 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1309 TRACKBAR_RecalculateTics (infoPtr);
1311 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1313 return 0;
1317 static inline LRESULT
1318 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1320 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1321 infoPtr->lSelMin = 0;
1322 infoPtr->lSelMax = 0;
1323 return 0;
1326 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1327 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1328 infoPtr->flags |= TB_SELECTIONCHANGED;
1330 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1331 infoPtr->lSelMin = infoPtr->lRangeMin;
1332 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1333 infoPtr->lSelMax = infoPtr->lRangeMax;
1335 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1337 return 0;
1341 static inline LRESULT
1342 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1344 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1345 infoPtr->lSelMax = 0;
1346 return 0;
1349 infoPtr->lSelMax = lEnd;
1350 infoPtr->flags |= TB_SELECTIONCHANGED;
1352 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1353 infoPtr->lSelMax = infoPtr->lRangeMax;
1355 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1357 return 0;
1361 static inline LRESULT
1362 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1364 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1365 infoPtr->lSelMin = 0;
1366 return 0;
1369 infoPtr->lSelMin = lStart;
1370 infoPtr->flags |=TB_SELECTIONCHANGED;
1372 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1373 infoPtr->lSelMin = infoPtr->lRangeMin;
1375 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1377 return 0;
1381 static inline LRESULT
1382 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1384 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1385 /* We're not supposed to check if it's really changed or not,
1386 just repaint in any case. */
1387 infoPtr->uThumbLen = iLength;
1388 infoPtr->flags |= TB_THUMBSIZECHANGED;
1389 TRACKBAR_InvalidateAll(infoPtr);
1392 return 0;
1396 static inline LRESULT
1397 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1399 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1400 return FALSE;
1402 TRACE("lPos=%d\n", lPos);
1404 infoPtr->uNumTics++;
1405 infoPtr->tics=ReAlloc( infoPtr->tics,
1406 (infoPtr->uNumTics)*sizeof (DWORD));
1407 if (!infoPtr->tics) {
1408 infoPtr->uNumTics = 0;
1409 notify(infoPtr, NM_OUTOFMEMORY);
1410 return FALSE;
1412 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1414 TRACKBAR_InvalidateAll(infoPtr);
1416 return TRUE;
1420 static inline LRESULT
1421 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1423 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1424 infoPtr->uTicFreq = wFreq;
1425 TRACKBAR_RecalculateTics (infoPtr);
1426 TRACKBAR_InvalidateAll(infoPtr);
1429 return 0;
1433 static inline INT
1434 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1436 INT fTemp = infoPtr->fLocation;
1438 infoPtr->fLocation = fLocation;
1440 return fTemp;
1444 static inline LRESULT
1445 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1447 infoPtr->hwndToolTip = hwndTT;
1449 return 0;
1453 static inline BOOL
1454 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1456 BOOL bTemp = infoPtr->bUnicode;
1458 infoPtr->bUnicode = fUnicode;
1460 return bTemp;
1464 static LRESULT
1465 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1467 RECT rect;
1468 int clientWidth, clientMetric;
1470 /* initial thumb length */
1471 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1472 GetClientRect(infoPtr->hwndSelf,&rect);
1473 if (infoPtr->dwStyle & TBS_VERT) {
1474 clientWidth = rect.right - rect.left;
1475 } else {
1476 clientWidth = rect.bottom - rect.top;
1478 if (clientWidth >= clientMetric)
1479 infoPtr->uThumbLen = clientMetric;
1480 else
1481 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1483 TRACKBAR_CalcChannel (infoPtr);
1484 TRACKBAR_UpdateThumb (infoPtr);
1485 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1487 return 0;
1491 static LRESULT
1492 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1494 TRACKBAR_INFO *infoPtr;
1496 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1497 if (!infoPtr) return -1;
1498 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1500 /* set default values */
1501 infoPtr->hwndSelf = hwnd;
1502 infoPtr->dwStyle = lpcs->style;
1503 infoPtr->lRangeMin = 0;
1504 infoPtr->lRangeMax = 100;
1505 infoPtr->lLineSize = 1;
1506 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1507 infoPtr->lSelMin = 0;
1508 infoPtr->lSelMax = 0;
1509 infoPtr->lPos = 0;
1510 infoPtr->fLocation = TBTS_TOP;
1511 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1512 infoPtr->uTicFreq = 1;
1513 infoPtr->tics = NULL;
1514 infoPtr->hwndNotify= lpcs->hwndParent;
1516 TRACKBAR_InitializeThumb (infoPtr);
1518 /* Create tooltip control */
1519 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1521 infoPtr->hwndToolTip =
1522 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1523 CW_USEDEFAULT, CW_USEDEFAULT,
1524 CW_USEDEFAULT, CW_USEDEFAULT,
1525 hwnd, 0, 0, 0);
1527 if (infoPtr->hwndToolTip) {
1528 TTTOOLINFOW ti;
1529 WCHAR wEmpty = 0;
1530 ZeroMemory (&ti, sizeof(ti));
1531 ti.cbSize = sizeof(ti);
1532 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1533 ti.hwnd = hwnd;
1534 ti.lpszText = &wEmpty;
1536 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1540 OpenThemeData (hwnd, themeClass);
1542 return 0;
1546 static LRESULT
1547 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1549 /* delete tooltip control */
1550 if (infoPtr->hwndToolTip)
1551 DestroyWindow (infoPtr->hwndToolTip);
1553 Free (infoPtr->tics);
1554 infoPtr->tics = NULL;
1556 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1557 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1558 Free (infoPtr);
1560 return 0;
1564 static LRESULT
1565 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1567 TRACE("\n");
1568 infoPtr->bFocussed = FALSE;
1569 TRACKBAR_InvalidateAll(infoPtr);
1571 return 0;
1574 static LRESULT
1575 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1577 POINT clickPoint;
1579 clickPoint.x = x;
1580 clickPoint.y = y;
1582 SetFocus(infoPtr->hwndSelf);
1584 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1585 infoPtr->flags |= TB_DRAG_MODE;
1586 SetCapture (infoPtr->hwndSelf);
1587 TRACKBAR_UpdateToolTip (infoPtr);
1588 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1589 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1590 } else {
1591 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1592 if (dir == 0) return 0;
1593 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1594 TRACKBAR_AutoPage (infoPtr, clickPoint);
1595 SetCapture (infoPtr->hwndSelf);
1596 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1599 return 0;
1603 static LRESULT
1604 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1606 if (infoPtr->flags & TB_DRAG_MODE) {
1607 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1608 notify_with_scroll (infoPtr, TB_ENDTRACK);
1609 infoPtr->flags &= ~TB_DRAG_MODE;
1610 ReleaseCapture ();
1611 notify(infoPtr, NM_RELEASEDCAPTURE);
1612 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1613 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1615 if (infoPtr->flags & TB_AUTO_PAGE) {
1616 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1617 infoPtr->flags &= ~TB_AUTO_PAGE;
1618 notify_with_scroll (infoPtr, TB_ENDTRACK);
1619 ReleaseCapture ();
1620 notify(infoPtr, NM_RELEASEDCAPTURE);
1623 return 0;
1627 static LRESULT
1628 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1630 notify_with_scroll (infoPtr, TB_ENDTRACK);
1631 return 0;
1635 static LRESULT
1636 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1638 if (hdc) {
1639 TRACKBAR_Refresh(infoPtr, hdc);
1640 } else {
1641 PAINTSTRUCT ps;
1642 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1643 TRACKBAR_Refresh (infoPtr, hdc);
1644 EndPaint (infoPtr->hwndSelf, &ps);
1647 return 0;
1651 static LRESULT
1652 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1654 TRACE("\n");
1655 infoPtr->bFocussed = TRUE;
1656 TRACKBAR_InvalidateAll(infoPtr);
1658 return 0;
1662 static LRESULT
1663 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1665 if (infoPtr->dwStyle & TBS_FIXEDLENGTH)
1667 TRACKBAR_CalcChannel(infoPtr);
1668 TRACKBAR_UpdateThumb(infoPtr);
1670 else
1671 TRACKBAR_InitializeThumb(infoPtr);
1672 TRACKBAR_AlignBuddies (infoPtr);
1673 TRACKBAR_InvalidateAll(infoPtr);
1675 return 0;
1678 static LRESULT
1679 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1680 const STYLESTRUCT *lpss)
1682 if (wStyleType != GWL_STYLE) return 0;
1684 infoPtr->dwStyle = lpss->styleNew;
1686 return 0;
1689 static LRESULT
1690 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1692 if (infoPtr->flags & TB_AUTO_PAGE) {
1693 POINT pt;
1694 if (GetCursorPos(&pt))
1695 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1696 TRACKBAR_AutoPage(infoPtr, pt);
1698 return 0;
1702 /* update theme after a WM_THEMECHANGED message */
1703 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1705 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1706 CloseThemeData (theme);
1707 OpenThemeData (infoPtr->hwndSelf, themeClass);
1708 return 0;
1712 static LRESULT
1713 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1715 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1716 LONG dragPos, oldPos = infoPtr->lPos;
1718 TRACE("(x=%d. y=%d)\n", x, y);
1720 if (infoPtr->flags & TB_AUTO_PAGE) {
1721 POINT pt;
1722 pt.x = x;
1723 pt.y = y;
1724 TRACKBAR_AutoPage (infoPtr, pt);
1725 return TRUE;
1728 if (!(infoPtr->flags & TB_DRAG_MODE))
1730 if (GetWindowTheme (infoPtr->hwndSelf))
1732 DWORD oldFlags = infoPtr->flags;
1733 POINT pt;
1734 pt.x = x;
1735 pt.y = y;
1736 if (PtInRect (&infoPtr->rcThumb, pt))
1738 TRACKMOUSEEVENT tme;
1739 tme.cbSize = sizeof( tme );
1740 tme.dwFlags = TME_LEAVE;
1741 tme.hwndTrack = infoPtr->hwndSelf;
1742 TrackMouseEvent( &tme );
1743 infoPtr->flags |= TB_THUMB_HOT;
1745 else
1747 TRACKMOUSEEVENT tme;
1748 tme.cbSize = sizeof( tme );
1749 tme.dwFlags = TME_CANCEL;
1750 tme.hwndTrack = infoPtr->hwndSelf;
1751 TrackMouseEvent( &tme );
1752 infoPtr->flags &= ~TB_THUMB_HOT;
1754 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1756 return TRUE;
1759 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1761 if (dragPos == oldPos) return TRUE;
1763 infoPtr->lPos = dragPos;
1764 TRACKBAR_UpdateThumb (infoPtr);
1766 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1768 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1769 UpdateWindow (infoPtr->hwndSelf);
1771 return TRUE;
1774 static BOOL
1775 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1777 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1778 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1779 LONG pos = infoPtr->lPos;
1781 TRACE("%x\n", nVirtKey);
1783 switch (nVirtKey) {
1784 case VK_UP:
1785 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1786 else TRACKBAR_LineUp(infoPtr);
1787 break;
1788 case VK_LEFT:
1789 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1790 else TRACKBAR_LineUp(infoPtr);
1791 break;
1792 case VK_DOWN:
1793 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1794 else TRACKBAR_LineDown(infoPtr);
1795 break;
1796 case VK_RIGHT:
1797 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1798 else TRACKBAR_LineDown(infoPtr);
1799 break;
1800 case VK_NEXT:
1801 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1802 else TRACKBAR_PageDown(infoPtr);
1803 break;
1804 case VK_PRIOR:
1805 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1806 else TRACKBAR_PageUp(infoPtr);
1807 break;
1808 case VK_HOME:
1809 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1810 infoPtr->lPos = infoPtr->lRangeMin;
1811 notify_with_scroll (infoPtr, TB_TOP);
1812 break;
1813 case VK_END:
1814 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1815 infoPtr->lPos = infoPtr->lRangeMax;
1816 notify_with_scroll (infoPtr, TB_BOTTOM);
1817 break;
1820 if (pos != infoPtr->lPos) {
1821 infoPtr->flags |=TB_THUMBPOSCHANGED;
1822 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1825 return TRUE;
1829 static inline BOOL
1830 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1832 switch (nVirtKey) {
1833 case VK_LEFT:
1834 case VK_UP:
1835 case VK_RIGHT:
1836 case VK_DOWN:
1837 case VK_NEXT:
1838 case VK_PRIOR:
1839 case VK_HOME:
1840 case VK_END:
1841 notify_with_scroll (infoPtr, TB_ENDTRACK);
1843 return TRUE;
1847 static LRESULT
1848 TRACKBAR_Enable (TRACKBAR_INFO *infoPtr, BOOL enable)
1850 if (enable)
1851 infoPtr->dwStyle &= ~WS_DISABLED;
1852 else
1853 infoPtr->dwStyle |= WS_DISABLED;
1855 InvalidateRect(infoPtr->hwndSelf, &infoPtr->rcThumb, TRUE);
1857 return 1;
1860 static LRESULT WINAPI
1861 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1863 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1865 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1867 if (!infoPtr && (uMsg != WM_CREATE))
1868 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1870 switch (uMsg)
1872 case TBM_CLEARSEL:
1873 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1875 case TBM_CLEARTICS:
1876 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1878 case TBM_GETBUDDY:
1879 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1881 case TBM_GETCHANNELRECT:
1882 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1884 case TBM_GETLINESIZE:
1885 return infoPtr->lLineSize;
1887 case TBM_GETNUMTICS:
1888 return TRACKBAR_GetNumTics (infoPtr);
1890 case TBM_GETPAGESIZE:
1891 return infoPtr->lPageSize;
1893 case TBM_GETPOS:
1894 return infoPtr->lPos;
1896 case TBM_GETPTICS:
1897 return (LRESULT)infoPtr->tics;
1899 case TBM_GETRANGEMAX:
1900 return infoPtr->lRangeMax;
1902 case TBM_GETRANGEMIN:
1903 return infoPtr->lRangeMin;
1905 case TBM_GETSELEND:
1906 return infoPtr->lSelMax;
1908 case TBM_GETSELSTART:
1909 return infoPtr->lSelMin;
1911 case TBM_GETTHUMBLENGTH:
1912 return infoPtr->uThumbLen;
1914 case TBM_GETTHUMBRECT:
1915 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1917 case TBM_GETTIC:
1918 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1920 case TBM_GETTICPOS:
1921 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1923 case TBM_GETTOOLTIPS:
1924 return (LRESULT)infoPtr->hwndToolTip;
1926 case TBM_GETUNICODEFORMAT:
1927 return infoPtr->bUnicode;
1929 case TBM_SETBUDDY:
1930 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1932 case TBM_SETLINESIZE:
1933 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1935 case TBM_SETPAGESIZE:
1936 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1938 case TBM_SETPOS:
1939 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1941 case TBM_SETRANGE:
1942 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1944 case TBM_SETRANGEMAX:
1945 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1947 case TBM_SETRANGEMIN:
1948 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1950 case TBM_SETSEL:
1951 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1953 case TBM_SETSELEND:
1954 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1956 case TBM_SETSELSTART:
1957 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1959 case TBM_SETTHUMBLENGTH:
1960 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1962 case TBM_SETTIC:
1963 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1965 case TBM_SETTICFREQ:
1966 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1968 case TBM_SETTIPSIDE:
1969 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1971 case TBM_SETTOOLTIPS:
1972 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1974 case TBM_SETUNICODEFORMAT:
1975 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1978 case WM_CAPTURECHANGED:
1979 return TRACKBAR_CaptureChanged (infoPtr);
1981 case WM_CREATE:
1982 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1984 case WM_DESTROY:
1985 return TRACKBAR_Destroy (infoPtr);
1987 case WM_ENABLE:
1988 return TRACKBAR_Enable (infoPtr, (BOOL)wParam);
1990 case WM_ERASEBKGND:
1991 return 0;
1993 case WM_GETDLGCODE:
1994 return DLGC_WANTARROWS;
1996 case WM_KEYDOWN:
1997 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
1999 case WM_KEYUP:
2000 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
2002 case WM_KILLFOCUS:
2003 return TRACKBAR_KillFocus (infoPtr);
2005 case WM_LBUTTONDOWN:
2006 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2008 case WM_LBUTTONUP:
2009 return TRACKBAR_LButtonUp (infoPtr);
2011 case WM_MOUSELEAVE:
2012 infoPtr->flags &= ~TB_THUMB_HOT;
2013 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
2014 return 0;
2016 case WM_MOUSEMOVE:
2017 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2019 case WM_PRINTCLIENT:
2020 case WM_PAINT:
2021 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
2023 case WM_SETFOCUS:
2024 return TRACKBAR_SetFocus (infoPtr);
2026 case WM_SIZE:
2027 return TRACKBAR_Size (infoPtr);
2029 case WM_STYLECHANGED:
2030 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2032 case WM_THEMECHANGED:
2033 return theme_changed (infoPtr);
2035 case WM_TIMER:
2036 return TRACKBAR_Timer (infoPtr);
2038 case WM_WININICHANGE:
2039 return TRACKBAR_InitializeThumb (infoPtr);
2041 default:
2042 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2043 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2044 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2049 void TRACKBAR_Register (void)
2051 WNDCLASSW wndClass;
2053 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2054 wndClass.style = CS_GLOBALCLASS;
2055 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
2056 wndClass.cbClsExtra = 0;
2057 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
2058 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2059 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2060 wndClass.lpszClassName = TRACKBAR_CLASSW;
2062 RegisterClassW (&wndClass);
2066 void TRACKBAR_Unregister (void)
2068 UnregisterClassW (TRACKBAR_CLASSW, NULL);