comctl32/trackbar: Update thumb on range change.
[wine.git] / dlls / comctl32 / trackbar.c
blobf79cc67ffbfb0065eec7cd17b60f6fb84791923c
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 SetRect(&rcTics, infoPtr->rcThumb.left - 2, infoPtr->rcChannel.top + offsetthumb,
501 infoPtr->rcThumb.right + 2, infoPtr->rcChannel.bottom - offsetthumb - 1);
502 } else {
503 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
504 SetRect(&rcTics, infoPtr->rcChannel.left + offsetthumb, infoPtr->rcThumb.top - 2,
505 infoPtr->rcChannel.right - offsetthumb - 1, infoPtr->rcThumb.bottom + 2);
508 if (flags & (TBS_TOP | TBS_LEFT)) {
509 x = rcTics.left;
510 y = rcTics.top;
511 side = -1;
512 } else {
513 x = rcTics.right;
514 y = rcTics.bottom;
515 side = 1;
518 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
519 if (range <= 0)
520 range = 1; /* to avoid division by zero */
522 if (flags & TIC_SELECTIONMARK) {
523 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
524 } else if (flags & TIC_EDGE) {
525 len++;
528 if (flags & TBS_VERT) {
529 int height = rcTics.bottom - rcTics.top;
530 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
531 } else {
532 int width = rcTics.right - rcTics.left;
533 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
536 ox = x;
537 oy = y;
538 MoveToEx(hdc, x, y, 0);
539 if (flags & TBS_VERT) x += len * side;
540 else y += len * side;
541 LineTo(hdc, x, y);
543 if (flags & TIC_SELECTIONMARK) {
544 if (flags & TBS_VERT) {
545 x -= side;
546 } else {
547 y -= side;
549 MoveToEx(hdc, x, y, 0);
550 if (flags & TBS_VERT) {
551 y += 2 * indent;
552 } else {
553 x += 2 * indent;
556 LineTo(hdc, x, y);
557 LineTo(hdc, ox, oy);
562 static inline void
563 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
565 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
566 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
568 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
569 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
572 static void
573 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc)
575 unsigned int i;
576 int ticFlags = infoPtr->dwStyle & 0x0f;
577 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
578 HPEN hOldPen, hTicPen;
579 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
581 if (theme)
583 int part = (infoPtr->dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
584 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
586 /* create the pen to draw the tics with */
587 hTicPen = CreatePenIndirect(&ticPen);
588 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
590 /* actually draw the tics */
591 for (i=0; i<infoPtr->uNumTics; i++)
592 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
594 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
595 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
597 if ((infoPtr->dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
599 ticFlags | TIC_SELECTIONMARKMIN);
600 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
601 ticFlags | TIC_SELECTIONMARKMAX);
604 /* clean up the pen, if we created one */
605 if (hTicPen) {
606 SelectObject(hdc, hOldPen);
607 DeleteObject(hTicPen);
611 static int
612 TRACKBAR_FillThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, HBRUSH hbrush)
614 const RECT *thumb = &infoPtr->rcThumb;
615 POINT points[6];
616 int PointDepth;
617 HBRUSH oldbr;
619 if (infoPtr->dwStyle & TBS_BOTH)
621 FillRect(hdc, thumb, hbrush);
622 return 0;
625 if (infoPtr->dwStyle & TBS_VERT)
627 PointDepth = (thumb->bottom - thumb->top) / 2;
628 if (infoPtr->dwStyle & TBS_LEFT)
630 points[0].x = thumb->right-1;
631 points[0].y = thumb->top;
632 points[1].x = thumb->right-1;
633 points[1].y = thumb->bottom-1;
634 points[2].x = thumb->left + PointDepth;
635 points[2].y = thumb->bottom-1;
636 points[3].x = thumb->left;
637 points[3].y = thumb->top + PointDepth;
638 points[4].x = thumb->left + PointDepth;
639 points[4].y = thumb->top;
640 points[5].x = points[0].x;
641 points[5].y = points[0].y;
643 else
645 points[0].x = thumb->right;
646 points[0].y = thumb->top + PointDepth;
647 points[1].x = thumb->right - PointDepth;
648 points[1].y = thumb->bottom-1;
649 points[2].x = thumb->left;
650 points[2].y = thumb->bottom-1;
651 points[3].x = thumb->left;
652 points[3].y = thumb->top;
653 points[4].x = thumb->right - PointDepth;
654 points[4].y = thumb->top;
655 points[5].x = points[0].x;
656 points[5].y = points[0].y;
659 else
661 PointDepth = (thumb->right - thumb->left) / 2;
662 if (infoPtr->dwStyle & TBS_TOP)
664 points[0].x = thumb->left + PointDepth;
665 points[0].y = thumb->top+1;
666 points[1].x = thumb->right-1;
667 points[1].y = thumb->top + PointDepth + 1;
668 points[2].x = thumb->right-1;
669 points[2].y = thumb->bottom-1;
670 points[3].x = thumb->left;
671 points[3].y = thumb->bottom-1;
672 points[4].x = thumb->left;
673 points[4].y = thumb->top + PointDepth + 1;
674 points[5].x = points[0].x;
675 points[5].y = points[0].y;
677 else
679 points[0].x = thumb->right-1;
680 points[0].y = thumb->top;
681 points[1].x = thumb->right-1;
682 points[1].y = thumb->bottom - PointDepth - 1;
683 points[2].x = thumb->left + PointDepth;
684 points[2].y = thumb->bottom-1;
685 points[3].x = thumb->left;
686 points[3].y = thumb->bottom - PointDepth - 1;
687 points[4].x = thumb->left;
688 points[4].y = thumb->top;
689 points[5].x = points[0].x;
690 points[5].y = points[0].y;
694 oldbr = SelectObject(hdc, hbrush);
695 SetPolyFillMode(hdc, WINDING);
696 Polygon(hdc, points, sizeof(points) / sizeof(points[0]));
697 SelectObject(hdc, oldbr);
699 return PointDepth;
702 static void
703 TRACKBAR_DrawThumb (TRACKBAR_INFO *infoPtr, HDC hdc)
705 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
706 int PointDepth;
707 HBRUSH brush;
709 if (theme)
711 int partId;
712 int stateId;
713 if (infoPtr->dwStyle & TBS_BOTH)
714 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
715 else if (infoPtr->dwStyle & TBS_LEFT)
716 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
717 else
718 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
720 if (infoPtr->dwStyle & WS_DISABLED)
721 stateId = TUS_DISABLED;
722 else if (infoPtr->flags & TB_DRAG_MODE)
723 stateId = TUS_PRESSED;
724 else if (infoPtr->flags & TB_THUMB_HOT)
725 stateId = TUS_HOT;
726 else
727 stateId = TUS_NORMAL;
729 DrawThemeBackground (theme, hdc, partId, stateId, &infoPtr->rcThumb, NULL);
731 return;
734 if (infoPtr->dwStyle & WS_DISABLED || infoPtr->flags & TB_DRAG_MODE)
736 if (comctl32_color.clr3dHilight == comctl32_color.clrWindow)
737 brush = COMCTL32_hPattern55AABrush;
738 else
739 brush = GetSysColorBrush(COLOR_SCROLLBAR);
741 SetTextColor(hdc, comctl32_color.clr3dFace);
742 SetBkColor(hdc, comctl32_color.clr3dHilight);
744 else
745 brush = GetSysColorBrush(COLOR_BTNFACE);
747 PointDepth = TRACKBAR_FillThumb(infoPtr, hdc, brush);
749 if (infoPtr->dwStyle & TBS_BOTH)
751 DrawEdge(hdc, &infoPtr->rcThumb, EDGE_RAISED, BF_RECT | BF_SOFT);
752 return;
754 else
756 RECT thumb = infoPtr->rcThumb;
758 if (infoPtr->dwStyle & TBS_VERT)
760 if (infoPtr->dwStyle & TBS_LEFT)
762 /* rectangular part */
763 thumb.left += PointDepth;
764 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_RIGHT | BF_BOTTOM | BF_SOFT);
766 /* light edge */
767 thumb.left -= PointDepth;
768 thumb.right = thumb.left + PointDepth;
769 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
770 thumb.top = infoPtr->rcThumb.top;
771 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
773 /* shadowed edge */
774 thumb.top += PointDepth;
775 thumb.bottom += PointDepth;
776 DrawEdge(hdc, &thumb, EDGE_SUNKEN, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
777 return;
779 else
781 /* rectangular part */
782 thumb.right -= PointDepth;
783 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_LEFT | BF_BOTTOM | BF_SOFT);
785 /* light edge */
786 thumb.left = thumb.right;
787 thumb.right += PointDepth + 1;
788 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
789 thumb.top = infoPtr->rcThumb.top;
790 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
792 /* shadowed edge */
793 thumb.top += PointDepth;
794 thumb.bottom += PointDepth;
795 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
798 else
800 if (infoPtr->dwStyle & TBS_TOP)
802 /* rectangular part */
803 thumb.top += PointDepth;
804 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_BOTTOM | BF_RIGHT | BF_SOFT);
806 /* light edge */
807 thumb.left = infoPtr->rcThumb.left;
808 thumb.right = thumb.left + PointDepth;
809 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
810 thumb.top -= PointDepth;
811 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
813 /* shadowed edge */
814 thumb.left += PointDepth;
815 thumb.right += PointDepth;
816 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMRIGHT | BF_SOFT);
818 else
820 /* rectangular part */
821 thumb.bottom -= PointDepth;
822 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT);
824 /* light edge */
825 thumb.left = infoPtr->rcThumb.left;
826 thumb.right = thumb.left + PointDepth;
827 thumb.top = infoPtr->rcThumb.bottom - PointDepth - 1;
828 thumb.bottom += PointDepth;
829 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
831 /* shadowed edge */
832 thumb.left += PointDepth;
833 thumb.right += PointDepth;
834 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
841 static inline void
842 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
844 TTTOOLINFOW ti;
846 if (!infoPtr->hwndToolTip) return;
848 ZeroMemory(&ti, sizeof(ti));
849 ti.cbSize = sizeof(ti);
850 ti.hwnd = infoPtr->hwndSelf;
852 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
856 static void
857 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
859 WCHAR buf[80];
860 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
861 TTTOOLINFOW ti;
862 POINT pt;
863 RECT rcClient;
864 LRESULT size;
866 if (!infoPtr->hwndToolTip) return;
868 ZeroMemory(&ti, sizeof(ti));
869 ti.cbSize = sizeof(ti);
870 ti.hwnd = infoPtr->hwndSelf;
871 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
873 wsprintfW (buf, fmt, infoPtr->lPos);
874 ti.lpszText = buf;
875 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
877 GetClientRect (infoPtr->hwndSelf, &rcClient);
878 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
879 if (infoPtr->dwStyle & TBS_VERT) {
880 if (infoPtr->fLocation == TBTS_LEFT)
881 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
882 else
883 pt.x = rcClient.right + TOOLTIP_OFFSET;
884 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
885 } else {
886 if (infoPtr->fLocation == TBTS_TOP)
887 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
888 else
889 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
890 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
892 ClientToScreen(infoPtr->hwndSelf, &pt);
894 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
895 0, MAKELPARAM(pt.x, pt.y));
899 static void
900 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
902 RECT rcClient;
903 HDC hdc;
904 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
905 NMCUSTOMDRAW nmcd;
906 int gcdrf, icdrf;
908 if (infoPtr->flags & TB_THUMBCHANGED) {
909 TRACKBAR_UpdateThumb (infoPtr);
910 if (infoPtr->flags & TB_THUMBSIZECHANGED)
911 TRACKBAR_CalcChannel (infoPtr);
913 if (infoPtr->flags & TB_SELECTIONCHANGED)
914 TRACKBAR_CalcSelection (infoPtr);
916 if (infoPtr->flags & TB_DRAG_MODE)
917 TRACKBAR_UpdateToolTip (infoPtr);
919 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
921 GetClientRect (infoPtr->hwndSelf, &rcClient);
923 /* try to render offscreen, if we fail, carrry onscreen */
924 hdc = CreateCompatibleDC(hdcDst);
925 if (hdc) {
926 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
927 if (hOffScreenBmp) {
928 hOldBmp = SelectObject(hdc, hOffScreenBmp);
929 } else {
930 DeleteObject(hdc);
931 hdc = hdcDst;
933 } else {
934 hdc = hdcDst;
937 ZeroMemory(&nmcd, sizeof(nmcd));
938 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
939 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
940 nmcd.hdr.code = NM_CUSTOMDRAW;
941 nmcd.hdc = hdc;
943 /* start the paint cycle */
944 nmcd.rc = rcClient;
945 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
946 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
948 /* Erase background */
949 if (gcdrf == CDRF_DODEFAULT ||
950 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
951 if (GetWindowTheme (infoPtr->hwndSelf)) {
952 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
954 else
955 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
956 if (gcdrf != CDRF_DODEFAULT)
957 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
960 /* draw channel */
961 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
962 nmcd.dwItemSpec = TBCD_CHANNEL;
963 nmcd.uItemState = CDIS_DEFAULT;
964 nmcd.rc = infoPtr->rcChannel;
965 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
966 } else icdrf = CDRF_DODEFAULT;
967 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
968 TRACKBAR_DrawChannel (infoPtr, hdc);
969 if (icdrf & CDRF_NOTIFYPOSTPAINT)
970 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
974 /* draw tics */
975 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
976 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
977 nmcd.dwItemSpec = TBCD_TICS;
978 nmcd.uItemState = CDIS_DEFAULT;
979 nmcd.rc = rcClient;
980 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
981 } else icdrf = CDRF_DODEFAULT;
982 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
983 TRACKBAR_DrawTics (infoPtr, hdc);
984 if (icdrf & CDRF_NOTIFYPOSTPAINT)
985 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
989 /* draw thumb */
990 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
991 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
992 nmcd.dwItemSpec = TBCD_THUMB;
993 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
994 nmcd.rc = infoPtr->rcThumb;
995 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
996 } else icdrf = CDRF_DODEFAULT;
997 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
998 TRACKBAR_DrawThumb(infoPtr, hdc);
999 if (icdrf & CDRF_NOTIFYPOSTPAINT)
1000 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
1004 /* draw focus rectangle */
1005 if (infoPtr->bFocussed) {
1006 DrawFocusRect(hdc, &rcClient);
1009 /* finish up the painting */
1010 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
1011 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
1013 cleanup:
1014 /* cleanup, if we rendered offscreen */
1015 if (hdc != hdcDst) {
1016 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
1017 SelectObject(hdc, hOldBmp);
1018 DeleteObject(hOffScreenBmp);
1019 DeleteObject(hdc);
1024 static void
1025 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
1027 HWND hwndParent = GetParent (infoPtr->hwndSelf);
1028 RECT rcSelf, rcBuddy;
1029 INT x, y;
1031 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
1032 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
1034 /* align buddy left or above */
1035 if (infoPtr->hwndBuddyLA) {
1036 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
1037 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1039 if (infoPtr->dwStyle & TBS_VERT) {
1040 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1041 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1042 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
1044 else {
1045 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
1046 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1047 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1050 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
1051 SWP_NOZORDER | SWP_NOSIZE);
1055 /* align buddy right or below */
1056 if (infoPtr->hwndBuddyRB) {
1057 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
1058 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1060 if (infoPtr->dwStyle & TBS_VERT) {
1061 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1062 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1063 y = rcSelf.bottom;
1065 else {
1066 x = rcSelf.right;
1067 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1068 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1070 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
1071 SWP_NOZORDER | SWP_NOSIZE);
1076 static LRESULT
1077 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1079 infoPtr->lSelMin = 0;
1080 infoPtr->lSelMax = 0;
1081 infoPtr->flags |= TB_SELECTIONCHANGED;
1083 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1085 return 0;
1089 static LRESULT
1090 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1092 if (infoPtr->tics) {
1093 Free (infoPtr->tics);
1094 infoPtr->tics = NULL;
1095 infoPtr->uNumTics = 0;
1098 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1100 return 0;
1104 static inline LRESULT
1105 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1107 if (lprc == NULL) return 0;
1109 lprc->left = infoPtr->rcChannel.left;
1110 lprc->right = infoPtr->rcChannel.right;
1111 lprc->bottom = infoPtr->rcChannel.bottom;
1112 lprc->top = infoPtr->rcChannel.top;
1114 return 0;
1118 static inline LONG
1119 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1121 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1123 return infoPtr->uNumTics + 2;
1127 static int comp_tics (const void *ap, const void *bp)
1129 const DWORD a = *(const DWORD *)ap;
1130 const DWORD b = *(const DWORD *)bp;
1132 TRACE("(a=%d, b=%d)\n", a, b);
1133 if (a < b) return -1;
1134 if (a > b) return 1;
1135 return 0;
1139 static inline LONG
1140 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1142 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1143 return -1;
1145 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1146 return infoPtr->tics[iTic];
1150 static inline LONG
1151 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1153 LONG range, width, pos, tic;
1154 int offsetthumb;
1156 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1157 return -1;
1159 tic = TRACKBAR_GetTic (infoPtr, iTic);
1160 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1161 if (range <= 0) range = 1;
1162 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1163 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1164 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1166 return pos;
1170 static HWND
1171 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1173 HWND hwndTemp;
1175 if (fLocation) {
1176 /* buddy is left or above */
1177 hwndTemp = infoPtr->hwndBuddyLA;
1178 infoPtr->hwndBuddyLA = hwndBuddy;
1180 else {
1181 /* buddy is right or below */
1182 hwndTemp = infoPtr->hwndBuddyRB;
1183 infoPtr->hwndBuddyRB = hwndBuddy;
1186 TRACKBAR_AlignBuddies (infoPtr);
1188 return hwndTemp;
1192 static inline LONG
1193 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1195 LONG lTemp = infoPtr->lLineSize;
1197 infoPtr->lLineSize = lLineSize;
1199 return lTemp;
1203 static inline LONG
1204 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1206 LONG lTemp = infoPtr->lPageSize;
1208 if (lPageSize != -1)
1209 infoPtr->lPageSize = lPageSize;
1210 else
1211 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1213 return lTemp;
1217 static inline LRESULT
1218 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1220 LONG oldPos = infoPtr->lPos;
1221 infoPtr->lPos = lPosition;
1223 if (infoPtr->lPos < infoPtr->lRangeMin)
1224 infoPtr->lPos = infoPtr->lRangeMin;
1226 if (infoPtr->lPos > infoPtr->lRangeMax)
1227 infoPtr->lPos = infoPtr->lRangeMax;
1229 if (fPosition && oldPos != lPosition)
1231 TRACKBAR_UpdateThumb(infoPtr);
1232 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1235 return 0;
1239 static inline LRESULT
1240 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
1242 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1243 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1245 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1246 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1248 /* clip position to new min/max limit */
1249 if (infoPtr->lPos < infoPtr->lRangeMin)
1250 infoPtr->lPos = infoPtr->lRangeMin;
1252 if (infoPtr->lPos > infoPtr->lRangeMax)
1253 infoPtr->lPos = infoPtr->lRangeMax;
1255 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1256 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1258 if (changed) {
1259 if (infoPtr->dwStyle & TBS_AUTOTICKS)
1260 TRACKBAR_RecalculateTics (infoPtr);
1261 infoPtr->flags |= TB_THUMBPOSCHANGED;
1264 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1266 return 0;
1270 static inline LRESULT
1271 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1273 BOOL changed = infoPtr->lRangeMax != lMax;
1275 infoPtr->lRangeMax = lMax;
1276 if (infoPtr->lPos > infoPtr->lRangeMax) {
1277 infoPtr->lPos = infoPtr->lRangeMax;
1278 infoPtr->flags |= TB_THUMBPOSCHANGED;
1281 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1282 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1284 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1285 TRACKBAR_RecalculateTics (infoPtr);
1287 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1289 return 0;
1293 static inline LRESULT
1294 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1296 BOOL changed = infoPtr->lRangeMin != lMin;
1298 infoPtr->lRangeMin = lMin;
1299 if (infoPtr->lPos < infoPtr->lRangeMin) {
1300 infoPtr->lPos = infoPtr->lRangeMin;
1301 infoPtr->flags |= TB_THUMBPOSCHANGED;
1304 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1305 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1307 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1308 TRACKBAR_RecalculateTics (infoPtr);
1310 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1312 return 0;
1316 static inline LRESULT
1317 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1319 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1320 infoPtr->lSelMin = 0;
1321 infoPtr->lSelMax = 0;
1322 return 0;
1325 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1326 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1327 infoPtr->flags |= TB_SELECTIONCHANGED;
1329 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1330 infoPtr->lSelMin = infoPtr->lRangeMin;
1331 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1332 infoPtr->lSelMax = infoPtr->lRangeMax;
1334 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1336 return 0;
1340 static inline LRESULT
1341 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1343 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1344 infoPtr->lSelMax = 0;
1345 return 0;
1348 infoPtr->lSelMax = lEnd;
1349 infoPtr->flags |= TB_SELECTIONCHANGED;
1351 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1352 infoPtr->lSelMax = infoPtr->lRangeMax;
1354 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1356 return 0;
1360 static inline LRESULT
1361 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1363 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1364 infoPtr->lSelMin = 0;
1365 return 0;
1368 infoPtr->lSelMin = lStart;
1369 infoPtr->flags |=TB_SELECTIONCHANGED;
1371 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1372 infoPtr->lSelMin = infoPtr->lRangeMin;
1374 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1376 return 0;
1380 static inline LRESULT
1381 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1383 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1384 /* We're not supposed to check if it's really changed or not,
1385 just repaint in any case. */
1386 infoPtr->uThumbLen = iLength;
1387 infoPtr->flags |= TB_THUMBSIZECHANGED;
1388 TRACKBAR_InvalidateAll(infoPtr);
1391 return 0;
1395 static inline LRESULT
1396 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1398 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1399 return FALSE;
1401 TRACE("lPos=%d\n", lPos);
1403 infoPtr->uNumTics++;
1404 infoPtr->tics=ReAlloc( infoPtr->tics,
1405 (infoPtr->uNumTics)*sizeof (DWORD));
1406 if (!infoPtr->tics) {
1407 infoPtr->uNumTics = 0;
1408 notify(infoPtr, NM_OUTOFMEMORY);
1409 return FALSE;
1411 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1413 TRACKBAR_InvalidateAll(infoPtr);
1415 return TRUE;
1419 static inline LRESULT
1420 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1422 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1423 infoPtr->uTicFreq = wFreq;
1424 TRACKBAR_RecalculateTics (infoPtr);
1425 TRACKBAR_InvalidateAll(infoPtr);
1428 return 0;
1432 static inline INT
1433 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1435 INT fTemp = infoPtr->fLocation;
1437 infoPtr->fLocation = fLocation;
1439 return fTemp;
1443 static inline LRESULT
1444 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1446 infoPtr->hwndToolTip = hwndTT;
1448 return 0;
1452 static inline BOOL
1453 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1455 BOOL bTemp = infoPtr->bUnicode;
1457 infoPtr->bUnicode = fUnicode;
1459 return bTemp;
1463 static LRESULT
1464 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1466 RECT rect;
1467 int clientWidth, clientMetric;
1469 /* initial thumb length */
1470 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1471 GetClientRect(infoPtr->hwndSelf,&rect);
1472 if (infoPtr->dwStyle & TBS_VERT) {
1473 clientWidth = rect.right - rect.left;
1474 } else {
1475 clientWidth = rect.bottom - rect.top;
1477 if (clientWidth >= clientMetric)
1478 infoPtr->uThumbLen = clientMetric;
1479 else
1480 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1482 TRACKBAR_CalcChannel (infoPtr);
1483 TRACKBAR_UpdateThumb (infoPtr);
1484 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1486 return 0;
1490 static LRESULT
1491 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1493 TRACKBAR_INFO *infoPtr;
1495 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1496 if (!infoPtr) return -1;
1497 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1499 /* set default values */
1500 infoPtr->hwndSelf = hwnd;
1501 infoPtr->dwStyle = lpcs->style;
1502 infoPtr->lRangeMin = 0;
1503 infoPtr->lRangeMax = 100;
1504 infoPtr->lLineSize = 1;
1505 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1506 infoPtr->lSelMin = 0;
1507 infoPtr->lSelMax = 0;
1508 infoPtr->lPos = 0;
1509 infoPtr->fLocation = TBTS_TOP;
1510 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1511 infoPtr->uTicFreq = 1;
1512 infoPtr->tics = NULL;
1513 infoPtr->hwndNotify= lpcs->hwndParent;
1515 TRACKBAR_InitializeThumb (infoPtr);
1517 /* Create tooltip control */
1518 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1520 infoPtr->hwndToolTip =
1521 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1522 CW_USEDEFAULT, CW_USEDEFAULT,
1523 CW_USEDEFAULT, CW_USEDEFAULT,
1524 hwnd, 0, 0, 0);
1526 if (infoPtr->hwndToolTip) {
1527 TTTOOLINFOW ti;
1528 WCHAR wEmpty = 0;
1529 ZeroMemory (&ti, sizeof(ti));
1530 ti.cbSize = sizeof(ti);
1531 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1532 ti.hwnd = hwnd;
1533 ti.lpszText = &wEmpty;
1535 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1539 OpenThemeData (hwnd, themeClass);
1541 return 0;
1545 static LRESULT
1546 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1548 /* delete tooltip control */
1549 if (infoPtr->hwndToolTip)
1550 DestroyWindow (infoPtr->hwndToolTip);
1552 Free (infoPtr->tics);
1553 infoPtr->tics = NULL;
1555 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1556 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1557 Free (infoPtr);
1559 return 0;
1563 static LRESULT
1564 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1566 TRACE("\n");
1567 infoPtr->bFocussed = FALSE;
1568 TRACKBAR_InvalidateAll(infoPtr);
1570 return 0;
1573 static LRESULT
1574 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1576 POINT clickPoint;
1578 clickPoint.x = x;
1579 clickPoint.y = y;
1581 SetFocus(infoPtr->hwndSelf);
1583 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1584 infoPtr->flags |= TB_DRAG_MODE;
1585 SetCapture (infoPtr->hwndSelf);
1586 TRACKBAR_UpdateToolTip (infoPtr);
1587 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1588 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1589 } else {
1590 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1591 if (dir == 0) return 0;
1592 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1593 TRACKBAR_AutoPage (infoPtr, clickPoint);
1594 SetCapture (infoPtr->hwndSelf);
1595 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1598 return 0;
1602 static LRESULT
1603 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1605 if (infoPtr->flags & TB_DRAG_MODE) {
1606 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1607 notify_with_scroll (infoPtr, TB_ENDTRACK);
1608 infoPtr->flags &= ~TB_DRAG_MODE;
1609 ReleaseCapture ();
1610 notify(infoPtr, NM_RELEASEDCAPTURE);
1611 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1612 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1614 if (infoPtr->flags & TB_AUTO_PAGE) {
1615 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1616 infoPtr->flags &= ~TB_AUTO_PAGE;
1617 notify_with_scroll (infoPtr, TB_ENDTRACK);
1618 ReleaseCapture ();
1619 notify(infoPtr, NM_RELEASEDCAPTURE);
1622 return 0;
1626 static LRESULT
1627 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1629 notify_with_scroll (infoPtr, TB_ENDTRACK);
1630 return 0;
1634 static LRESULT
1635 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1637 if (hdc) {
1638 TRACKBAR_Refresh(infoPtr, hdc);
1639 } else {
1640 PAINTSTRUCT ps;
1641 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1642 TRACKBAR_Refresh (infoPtr, hdc);
1643 EndPaint (infoPtr->hwndSelf, &ps);
1646 return 0;
1650 static LRESULT
1651 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1653 TRACE("\n");
1654 infoPtr->bFocussed = TRUE;
1655 TRACKBAR_InvalidateAll(infoPtr);
1657 return 0;
1661 static LRESULT
1662 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1664 if (infoPtr->dwStyle & TBS_FIXEDLENGTH)
1666 TRACKBAR_CalcChannel(infoPtr);
1667 TRACKBAR_UpdateThumb(infoPtr);
1669 else
1670 TRACKBAR_InitializeThumb(infoPtr);
1671 TRACKBAR_AlignBuddies (infoPtr);
1672 TRACKBAR_InvalidateAll(infoPtr);
1674 return 0;
1677 static LRESULT
1678 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1679 const STYLESTRUCT *lpss)
1681 if (wStyleType != GWL_STYLE) return 0;
1683 infoPtr->dwStyle = lpss->styleNew;
1685 return 0;
1688 static LRESULT
1689 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1691 if (infoPtr->flags & TB_AUTO_PAGE) {
1692 POINT pt;
1693 if (GetCursorPos(&pt))
1694 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1695 TRACKBAR_AutoPage(infoPtr, pt);
1697 return 0;
1701 /* update theme after a WM_THEMECHANGED message */
1702 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1704 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1705 CloseThemeData (theme);
1706 OpenThemeData (infoPtr->hwndSelf, themeClass);
1707 return 0;
1711 static LRESULT
1712 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1714 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1715 LONG dragPos, oldPos = infoPtr->lPos;
1717 TRACE("(x=%d. y=%d)\n", x, y);
1719 if (infoPtr->flags & TB_AUTO_PAGE) {
1720 POINT pt;
1721 pt.x = x;
1722 pt.y = y;
1723 TRACKBAR_AutoPage (infoPtr, pt);
1724 return TRUE;
1727 if (!(infoPtr->flags & TB_DRAG_MODE))
1729 if (GetWindowTheme (infoPtr->hwndSelf))
1731 DWORD oldFlags = infoPtr->flags;
1732 POINT pt;
1733 pt.x = x;
1734 pt.y = y;
1735 if (PtInRect (&infoPtr->rcThumb, pt))
1737 TRACKMOUSEEVENT tme;
1738 tme.cbSize = sizeof( tme );
1739 tme.dwFlags = TME_LEAVE;
1740 tme.hwndTrack = infoPtr->hwndSelf;
1741 TrackMouseEvent( &tme );
1742 infoPtr->flags |= TB_THUMB_HOT;
1744 else
1746 TRACKMOUSEEVENT tme;
1747 tme.cbSize = sizeof( tme );
1748 tme.dwFlags = TME_CANCEL;
1749 tme.hwndTrack = infoPtr->hwndSelf;
1750 TrackMouseEvent( &tme );
1751 infoPtr->flags &= ~TB_THUMB_HOT;
1753 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1755 return TRUE;
1758 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1760 if (dragPos == oldPos) return TRUE;
1762 infoPtr->lPos = dragPos;
1763 TRACKBAR_UpdateThumb (infoPtr);
1765 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1767 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1768 UpdateWindow (infoPtr->hwndSelf);
1770 return TRUE;
1773 static BOOL
1774 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1776 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1777 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1778 LONG pos = infoPtr->lPos;
1780 TRACE("%x\n", nVirtKey);
1782 switch (nVirtKey) {
1783 case VK_UP:
1784 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1785 else TRACKBAR_LineUp(infoPtr);
1786 break;
1787 case VK_LEFT:
1788 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1789 else TRACKBAR_LineUp(infoPtr);
1790 break;
1791 case VK_DOWN:
1792 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1793 else TRACKBAR_LineDown(infoPtr);
1794 break;
1795 case VK_RIGHT:
1796 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1797 else TRACKBAR_LineDown(infoPtr);
1798 break;
1799 case VK_NEXT:
1800 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1801 else TRACKBAR_PageDown(infoPtr);
1802 break;
1803 case VK_PRIOR:
1804 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1805 else TRACKBAR_PageUp(infoPtr);
1806 break;
1807 case VK_HOME:
1808 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1809 infoPtr->lPos = infoPtr->lRangeMin;
1810 notify_with_scroll (infoPtr, TB_TOP);
1811 break;
1812 case VK_END:
1813 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1814 infoPtr->lPos = infoPtr->lRangeMax;
1815 notify_with_scroll (infoPtr, TB_BOTTOM);
1816 break;
1819 if (pos != infoPtr->lPos) {
1820 TRACKBAR_UpdateThumb (infoPtr);
1821 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1824 return TRUE;
1828 static inline BOOL
1829 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1831 switch (nVirtKey) {
1832 case VK_LEFT:
1833 case VK_UP:
1834 case VK_RIGHT:
1835 case VK_DOWN:
1836 case VK_NEXT:
1837 case VK_PRIOR:
1838 case VK_HOME:
1839 case VK_END:
1840 notify_with_scroll (infoPtr, TB_ENDTRACK);
1842 return TRUE;
1846 static LRESULT
1847 TRACKBAR_Enable (TRACKBAR_INFO *infoPtr, BOOL enable)
1849 if (enable)
1850 infoPtr->dwStyle &= ~WS_DISABLED;
1851 else
1852 infoPtr->dwStyle |= WS_DISABLED;
1854 InvalidateRect(infoPtr->hwndSelf, &infoPtr->rcThumb, TRUE);
1856 return 1;
1859 static LRESULT WINAPI
1860 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1862 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1864 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1866 if (!infoPtr && (uMsg != WM_CREATE))
1867 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1869 switch (uMsg)
1871 case TBM_CLEARSEL:
1872 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1874 case TBM_CLEARTICS:
1875 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1877 case TBM_GETBUDDY:
1878 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1880 case TBM_GETCHANNELRECT:
1881 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1883 case TBM_GETLINESIZE:
1884 return infoPtr->lLineSize;
1886 case TBM_GETNUMTICS:
1887 return TRACKBAR_GetNumTics (infoPtr);
1889 case TBM_GETPAGESIZE:
1890 return infoPtr->lPageSize;
1892 case TBM_GETPOS:
1893 return infoPtr->lPos;
1895 case TBM_GETPTICS:
1896 return (LRESULT)infoPtr->tics;
1898 case TBM_GETRANGEMAX:
1899 return infoPtr->lRangeMax;
1901 case TBM_GETRANGEMIN:
1902 return infoPtr->lRangeMin;
1904 case TBM_GETSELEND:
1905 return infoPtr->lSelMax;
1907 case TBM_GETSELSTART:
1908 return infoPtr->lSelMin;
1910 case TBM_GETTHUMBLENGTH:
1911 return infoPtr->uThumbLen;
1913 case TBM_GETTHUMBRECT:
1914 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1916 case TBM_GETTIC:
1917 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1919 case TBM_GETTICPOS:
1920 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1922 case TBM_GETTOOLTIPS:
1923 return (LRESULT)infoPtr->hwndToolTip;
1925 case TBM_GETUNICODEFORMAT:
1926 return infoPtr->bUnicode;
1928 case TBM_SETBUDDY:
1929 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1931 case TBM_SETLINESIZE:
1932 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1934 case TBM_SETPAGESIZE:
1935 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1937 case TBM_SETPOS:
1938 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1940 case TBM_SETRANGE:
1941 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1943 case TBM_SETRANGEMAX:
1944 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1946 case TBM_SETRANGEMIN:
1947 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1949 case TBM_SETSEL:
1950 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1952 case TBM_SETSELEND:
1953 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1955 case TBM_SETSELSTART:
1956 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1958 case TBM_SETTHUMBLENGTH:
1959 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1961 case TBM_SETTIC:
1962 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1964 case TBM_SETTICFREQ:
1965 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1967 case TBM_SETTIPSIDE:
1968 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1970 case TBM_SETTOOLTIPS:
1971 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1973 case TBM_SETUNICODEFORMAT:
1974 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1977 case WM_CAPTURECHANGED:
1978 if (hwnd == (HWND)lParam) return 0;
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);