comctl32: Use ARRAY_SIZE() macro.
[wine.git] / dlls / comctl32 / trackbar.c
blob92c8d9eef04828b6a763274a76632416e735b8aa
1 /*
2 * Trackbar control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1998, 1999 Alex Priem
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <math.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "commctrl.h"
35 #include "uxtheme.h"
36 #include "vssym32.h"
37 #include "wine/debug.h"
39 #include "comctl32.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
43 typedef struct
45 HWND hwndSelf;
46 DWORD dwStyle;
47 LONG lRangeMin;
48 LONG lRangeMax;
49 LONG lLineSize;
50 LONG lPageSize;
51 LONG lSelMin;
52 LONG lSelMax;
53 LONG lPos;
54 UINT uThumbLen;
55 UINT uNumTics;
56 UINT uTicFreq;
57 HWND hwndNotify;
58 HWND hwndToolTip;
59 HWND hwndBuddyLA;
60 HWND hwndBuddyRB;
61 INT fLocation;
62 INT flags;
63 BOOL bUnicode;
64 BOOL bFocussed;
65 RECT rcChannel;
66 RECT rcSelection;
67 RECT rcThumb;
68 LPLONG tics;
69 } TRACKBAR_INFO;
71 #define TB_REFRESH_TIMER 1
72 #define TB_REFRESH_DELAY 500
74 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
76 #define TB_DEFAULTPAGESIZE 20
78 /* Used by TRACKBAR_Refresh to find out which parts of the control
79 need to be recalculated */
81 #define TB_THUMBPOSCHANGED 1
82 #define TB_THUMBSIZECHANGED 2
83 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
84 #define TB_SELECTIONCHANGED 4
85 #define TB_DRAG_MODE 8 /* we're dragging the slider */
86 #define TB_AUTO_PAGE_LEFT 16
87 #define TB_AUTO_PAGE_RIGHT 32
88 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
89 #define TB_THUMB_HOT 64 /* mouse hovers above thumb */
91 /* helper defines for TRACKBAR_DrawTic */
92 #define TIC_EDGE 0x20
93 #define TIC_SELECTIONMARKMAX 0x80
94 #define TIC_SELECTIONMARKMIN 0x100
95 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
97 static const WCHAR themeClass[] = { 'T','r','a','c','k','b','a','r',0 };
99 static inline int
100 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
102 pnmcd->dwDrawStage = stage;
103 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
104 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
107 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
109 LRESULT result;
111 TRACE("(code=%d)\n", code);
113 pnmh->hwndFrom = infoPtr->hwndSelf;
114 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
115 pnmh->code = code;
116 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
118 TRACE(" <= %ld\n", result);
120 return result;
123 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
125 NMHDR nmh;
126 return notify_hdr(infoPtr, code, &nmh);
129 static void notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
131 UINT scroll = infoPtr->dwStyle & TBS_VERT ? WM_VSCROLL : WM_HSCROLL;
133 TRACE("%x\n", code);
135 SendMessageW (infoPtr->hwndNotify, scroll, code, (LPARAM)infoPtr->hwndSelf);
138 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
140 int tic;
141 unsigned nrTics, i;
143 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin) {
144 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
145 /* don't add extra tic if there's no remainder */
146 if (nrTics && ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0))
147 nrTics--;
149 else {
150 Free (infoPtr->tics);
151 infoPtr->tics = NULL;
152 infoPtr->uNumTics = 0;
153 return;
156 if (nrTics != infoPtr->uNumTics) {
157 infoPtr->tics=ReAlloc (infoPtr->tics,
158 (nrTics+1)*sizeof (DWORD));
159 if (!infoPtr->tics) {
160 infoPtr->uNumTics = 0;
161 notify(infoPtr, NM_OUTOFMEMORY);
162 return;
164 infoPtr->uNumTics = nrTics;
167 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
168 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
169 infoPtr->tics[i] = tic;
172 /* converts from physical (mouse) position to logical position
173 (in range of trackbar) */
175 static inline LONG
176 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place)
178 double range, width, pos, offsetthumb;
180 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
181 if (infoPtr->dwStyle & TBS_VERT) {
182 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
183 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
184 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
185 } else {
186 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
187 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
188 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
190 pos += infoPtr->lRangeMin;
191 if (pos > infoPtr->lRangeMax)
192 pos = infoPtr->lRangeMax;
193 else if (pos < infoPtr->lRangeMin)
194 pos = infoPtr->lRangeMin;
196 TRACE("%.2f\n", pos);
197 return (LONG)floor(pos + 0.5);
201 /* return: 0> prev, 0 none, >0 next */
202 static LONG
203 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
205 RECT pageRect;
207 if (infoPtr->dwStyle & TBS_VERT) {
208 pageRect.top = infoPtr->rcChannel.top;
209 pageRect.bottom = infoPtr->rcChannel.bottom;
210 pageRect.left = infoPtr->rcThumb.left;
211 pageRect.right = infoPtr->rcThumb.right;
212 } else {
213 pageRect.top = infoPtr->rcThumb.top;
214 pageRect.bottom = infoPtr->rcThumb.bottom;
215 pageRect.left = infoPtr->rcChannel.left;
216 pageRect.right = infoPtr->rcChannel.right;
220 if (PtInRect(&pageRect, clickPoint))
222 int clickPlace = (infoPtr->dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
224 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace);
226 return clickPos - infoPtr->lPos;
229 return 0;
232 static inline void
233 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
235 if (infoPtr->lPos == infoPtr->lRangeMax) return;
237 infoPtr->lPos += infoPtr->lPageSize;
238 if (infoPtr->lPos > infoPtr->lRangeMax)
239 infoPtr->lPos = infoPtr->lRangeMax;
240 notify_with_scroll (infoPtr, TB_PAGEDOWN);
244 static inline void
245 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
247 if (infoPtr->lPos == infoPtr->lRangeMin) return;
249 infoPtr->lPos -= infoPtr->lPageSize;
250 if (infoPtr->lPos < infoPtr->lRangeMin)
251 infoPtr->lPos = infoPtr->lRangeMin;
252 notify_with_scroll (infoPtr, TB_PAGEUP);
255 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
257 if (infoPtr->lPos == infoPtr->lRangeMin) return;
258 infoPtr->lPos -= infoPtr->lLineSize;
259 if (infoPtr->lPos < infoPtr->lRangeMin)
260 infoPtr->lPos = infoPtr->lRangeMin;
261 notify_with_scroll (infoPtr, TB_LINEUP);
264 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
266 if (infoPtr->lPos == infoPtr->lRangeMax) return;
267 infoPtr->lPos += infoPtr->lLineSize;
268 if (infoPtr->lPos > infoPtr->lRangeMax)
269 infoPtr->lPos = infoPtr->lRangeMax;
270 notify_with_scroll (infoPtr, TB_LINEDOWN);
273 static void
274 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
276 INT cyChannel, offsetthumb, offsetedge;
277 RECT lpRect, *channel = & infoPtr->rcChannel;
279 GetClientRect (infoPtr->hwndSelf, &lpRect);
281 offsetthumb = infoPtr->uThumbLen / 4;
282 offsetedge = offsetthumb + 3;
283 cyChannel = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
284 if (infoPtr->dwStyle & TBS_VERT) {
285 channel->top = lpRect.top + offsetedge;
286 channel->bottom = lpRect.bottom - offsetedge;
287 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
288 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
289 else
290 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
291 if (infoPtr->dwStyle & TBS_BOTH) {
292 if (infoPtr->dwStyle & TBS_NOTICKS)
293 channel->left += 1;
294 else
295 channel->left += 9;
297 else if (infoPtr->dwStyle & TBS_TOP) {
298 if (infoPtr->dwStyle & TBS_NOTICKS)
299 channel->left += 2;
300 else
301 channel->left += 10;
303 channel->right = channel->left + cyChannel;
304 } else {
305 channel->left = lpRect.left + offsetedge;
306 channel->right = lpRect.right - offsetedge;
307 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
308 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
309 else
310 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
311 if (infoPtr->dwStyle & TBS_BOTH) {
312 if (infoPtr->dwStyle & TBS_NOTICKS)
313 channel->top += 1;
314 else
315 channel->top += 9;
317 else if (infoPtr->dwStyle & TBS_TOP) {
318 if (infoPtr->dwStyle & TBS_NOTICKS)
319 channel->top += 2;
320 else
321 channel->top += 10;
323 channel->bottom = channel->top + cyChannel;
327 static void
328 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
330 int range, width, height, thumbwidth;
331 RECT lpRect;
333 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
334 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
336 if (!range) range = 1;
338 GetClientRect(infoPtr->hwndSelf, &lpRect);
339 if (infoPtr->dwStyle & TBS_VERT)
341 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
343 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_LEFT)) && !(infoPtr->dwStyle & TBS_NOTICKS))
344 thumb->left = 10;
345 else
346 thumb->left = 2;
347 thumb->right = thumb->left + infoPtr->uThumbLen;
348 thumb->top = infoPtr->rcChannel.top +
349 (height*(lPos - infoPtr->lRangeMin))/range;
350 thumb->bottom = thumb->top + thumbwidth;
352 else
354 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
356 thumb->left = infoPtr->rcChannel.left +
357 (width*(lPos - infoPtr->lRangeMin))/range;
358 thumb->right = thumb->left + thumbwidth;
359 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_TOP)) && !(infoPtr->dwStyle & TBS_NOTICKS))
360 thumb->top = 10;
361 else
362 thumb->top = 2;
363 thumb->bottom = thumb->top + infoPtr->uThumbLen;
367 static inline void
368 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
370 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
373 static inline void
374 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
376 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
379 static void
380 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
382 RECT rcThumb;
384 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
385 InflateRect(&rcThumb, 1, 1);
386 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
389 static inline void
390 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
392 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
393 if (newPos != oldPos)
394 TRACKBAR_InvalidateThumb (infoPtr, newPos);
397 static inline BOOL
398 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
400 return infoPtr->lSelMin != infoPtr->lSelMax;
403 static void
404 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
406 RECT *selection = &infoPtr->rcSelection;
407 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
408 int offsetthumb, height, width;
410 if (range <= 0) {
411 SetRectEmpty (selection);
412 } else {
413 if (infoPtr->dwStyle & TBS_VERT) {
414 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
415 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
416 selection->top = infoPtr->rcChannel.top + offsetthumb +
417 (height*infoPtr->lSelMin)/range;
418 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
419 (height*infoPtr->lSelMax)/range;
420 selection->left = infoPtr->rcChannel.left + 3;
421 selection->right = infoPtr->rcChannel.right - 3;
422 } else {
423 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
424 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
425 selection->left = infoPtr->rcChannel.left + offsetthumb +
426 (width*infoPtr->lSelMin)/range;
427 selection->right = infoPtr->rcChannel.left + offsetthumb +
428 (width*infoPtr->lSelMax)/range;
429 selection->top = infoPtr->rcChannel.top + 3;
430 selection->bottom = infoPtr->rcChannel.bottom - 3;
434 TRACE("selection[%s]\n", wine_dbgstr_rect(selection));
437 static BOOL
438 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
440 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
441 LONG prevPos = infoPtr->lPos;
443 TRACE("clickPoint=%s, dir=%d\n", wine_dbgstr_point(&clickPoint), dir);
445 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
446 TRACKBAR_PageDown(infoPtr);
447 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
448 TRACKBAR_PageUp(infoPtr);
449 else return FALSE;
451 TRACKBAR_UpdateThumb (infoPtr);
452 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
454 return TRUE;
457 /* Trackbar drawing code. I like my spaghetti done milanese. */
459 static void
460 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc)
462 RECT rcChannel = infoPtr->rcChannel;
463 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
465 if (theme)
467 DrawThemeBackground (theme, hdc,
468 (infoPtr->dwStyle & TBS_VERT) ?
469 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
471 else
473 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
474 if (infoPtr->dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
475 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
476 if (TRACKBAR_HasSelection(infoPtr))
477 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
482 static void
483 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
485 int x, y, ox, oy, range, side, indent = 0, len = 3;
486 int offsetthumb;
487 RECT rcTics;
489 if (flags & TBS_VERT) {
490 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
491 SetRect(&rcTics, infoPtr->rcThumb.left - 2, infoPtr->rcChannel.top + offsetthumb,
492 infoPtr->rcThumb.right + 2, infoPtr->rcChannel.bottom - offsetthumb - 1);
493 } else {
494 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
495 SetRect(&rcTics, infoPtr->rcChannel.left + offsetthumb, infoPtr->rcThumb.top - 2,
496 infoPtr->rcChannel.right - offsetthumb - 1, infoPtr->rcThumb.bottom + 2);
499 if (flags & (TBS_TOP | TBS_LEFT)) {
500 x = rcTics.left;
501 y = rcTics.top;
502 side = -1;
503 } else {
504 x = rcTics.right;
505 y = rcTics.bottom;
506 side = 1;
509 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
510 if (range <= 0)
511 range = 1; /* to avoid division by zero */
513 if (flags & TIC_SELECTIONMARK) {
514 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
515 } else if (flags & TIC_EDGE) {
516 len++;
519 if (flags & TBS_VERT) {
520 int height = rcTics.bottom - rcTics.top;
521 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
522 } else {
523 int width = rcTics.right - rcTics.left;
524 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
527 ox = x;
528 oy = y;
529 MoveToEx(hdc, x, y, 0);
530 if (flags & TBS_VERT) x += len * side;
531 else y += len * side;
532 LineTo(hdc, x, y);
534 if (flags & TIC_SELECTIONMARK) {
535 if (flags & TBS_VERT) {
536 x -= side;
537 } else {
538 y -= side;
540 MoveToEx(hdc, x, y, 0);
541 if (flags & TBS_VERT) {
542 y += 2 * indent;
543 } else {
544 x += 2 * indent;
547 LineTo(hdc, x, y);
548 LineTo(hdc, ox, oy);
553 static inline void
554 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
556 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
557 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
559 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
560 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
563 static void
564 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc)
566 unsigned int i;
567 int ticFlags = infoPtr->dwStyle & 0x0f;
568 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
569 HPEN hOldPen, hTicPen;
570 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
572 if (theme)
574 int part = (infoPtr->dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
575 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
577 /* create the pen to draw the tics with */
578 hTicPen = CreatePenIndirect(&ticPen);
579 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
581 /* actually draw the tics */
582 for (i=0; i<infoPtr->uNumTics; i++)
583 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
585 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
586 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
588 if ((infoPtr->dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
589 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
590 ticFlags | TIC_SELECTIONMARKMIN);
591 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
592 ticFlags | TIC_SELECTIONMARKMAX);
595 /* clean up the pen, if we created one */
596 if (hTicPen) {
597 SelectObject(hdc, hOldPen);
598 DeleteObject(hTicPen);
602 static int
603 TRACKBAR_FillThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, HBRUSH hbrush)
605 const RECT *thumb = &infoPtr->rcThumb;
606 POINT points[6];
607 int PointDepth;
608 HBRUSH oldbr;
610 if (infoPtr->dwStyle & TBS_BOTH)
612 FillRect(hdc, thumb, hbrush);
613 return 0;
616 if (infoPtr->dwStyle & TBS_VERT)
618 PointDepth = (thumb->bottom - thumb->top) / 2;
619 if (infoPtr->dwStyle & TBS_LEFT)
621 points[0].x = thumb->right-1;
622 points[0].y = thumb->top;
623 points[1].x = thumb->right-1;
624 points[1].y = thumb->bottom-1;
625 points[2].x = thumb->left + PointDepth;
626 points[2].y = thumb->bottom-1;
627 points[3].x = thumb->left;
628 points[3].y = thumb->top + PointDepth;
629 points[4].x = thumb->left + PointDepth;
630 points[4].y = thumb->top;
631 points[5].x = points[0].x;
632 points[5].y = points[0].y;
634 else
636 points[0].x = thumb->right;
637 points[0].y = thumb->top + PointDepth;
638 points[1].x = thumb->right - PointDepth;
639 points[1].y = thumb->bottom-1;
640 points[2].x = thumb->left;
641 points[2].y = thumb->bottom-1;
642 points[3].x = thumb->left;
643 points[3].y = thumb->top;
644 points[4].x = thumb->right - PointDepth;
645 points[4].y = thumb->top;
646 points[5].x = points[0].x;
647 points[5].y = points[0].y;
650 else
652 PointDepth = (thumb->right - thumb->left) / 2;
653 if (infoPtr->dwStyle & TBS_TOP)
655 points[0].x = thumb->left + PointDepth;
656 points[0].y = thumb->top+1;
657 points[1].x = thumb->right-1;
658 points[1].y = thumb->top + PointDepth + 1;
659 points[2].x = thumb->right-1;
660 points[2].y = thumb->bottom-1;
661 points[3].x = thumb->left;
662 points[3].y = thumb->bottom-1;
663 points[4].x = thumb->left;
664 points[4].y = thumb->top + PointDepth + 1;
665 points[5].x = points[0].x;
666 points[5].y = points[0].y;
668 else
670 points[0].x = thumb->right-1;
671 points[0].y = thumb->top;
672 points[1].x = thumb->right-1;
673 points[1].y = thumb->bottom - PointDepth - 1;
674 points[2].x = thumb->left + PointDepth;
675 points[2].y = thumb->bottom-1;
676 points[3].x = thumb->left;
677 points[3].y = thumb->bottom - PointDepth - 1;
678 points[4].x = thumb->left;
679 points[4].y = thumb->top;
680 points[5].x = points[0].x;
681 points[5].y = points[0].y;
685 oldbr = SelectObject(hdc, hbrush);
686 SetPolyFillMode(hdc, WINDING);
687 Polygon(hdc, points, ARRAY_SIZE(points));
688 SelectObject(hdc, oldbr);
690 return PointDepth;
693 static void
694 TRACKBAR_DrawThumb (TRACKBAR_INFO *infoPtr, HDC hdc)
696 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
697 int PointDepth;
698 HBRUSH brush;
700 if (theme)
702 int partId;
703 int stateId;
704 if (infoPtr->dwStyle & TBS_BOTH)
705 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
706 else if (infoPtr->dwStyle & TBS_LEFT)
707 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
708 else
709 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
711 if (infoPtr->dwStyle & WS_DISABLED)
712 stateId = TUS_DISABLED;
713 else if (infoPtr->flags & TB_DRAG_MODE)
714 stateId = TUS_PRESSED;
715 else if (infoPtr->flags & TB_THUMB_HOT)
716 stateId = TUS_HOT;
717 else
718 stateId = TUS_NORMAL;
720 DrawThemeBackground (theme, hdc, partId, stateId, &infoPtr->rcThumb, NULL);
722 return;
725 if (infoPtr->dwStyle & WS_DISABLED || infoPtr->flags & TB_DRAG_MODE)
727 if (comctl32_color.clr3dHilight == comctl32_color.clrWindow)
728 brush = COMCTL32_hPattern55AABrush;
729 else
730 brush = GetSysColorBrush(COLOR_SCROLLBAR);
732 SetTextColor(hdc, comctl32_color.clr3dFace);
733 SetBkColor(hdc, comctl32_color.clr3dHilight);
735 else
736 brush = GetSysColorBrush(COLOR_BTNFACE);
738 PointDepth = TRACKBAR_FillThumb(infoPtr, hdc, brush);
740 if (infoPtr->dwStyle & TBS_BOTH)
742 DrawEdge(hdc, &infoPtr->rcThumb, EDGE_RAISED, BF_RECT | BF_SOFT);
743 return;
745 else
747 RECT thumb = infoPtr->rcThumb;
749 if (infoPtr->dwStyle & TBS_VERT)
751 if (infoPtr->dwStyle & TBS_LEFT)
753 /* rectangular part */
754 thumb.left += PointDepth;
755 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_RIGHT | BF_BOTTOM | BF_SOFT);
757 /* light edge */
758 thumb.left -= PointDepth;
759 thumb.right = thumb.left + PointDepth;
760 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
761 thumb.top = infoPtr->rcThumb.top;
762 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
764 /* shadowed edge */
765 thumb.top += PointDepth;
766 thumb.bottom += PointDepth;
767 DrawEdge(hdc, &thumb, EDGE_SUNKEN, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
768 return;
770 else
772 /* rectangular part */
773 thumb.right -= PointDepth;
774 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_LEFT | BF_BOTTOM | BF_SOFT);
776 /* light edge */
777 thumb.left = thumb.right;
778 thumb.right += PointDepth + 1;
779 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
780 thumb.top = infoPtr->rcThumb.top;
781 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
783 /* shadowed edge */
784 thumb.top += PointDepth;
785 thumb.bottom += PointDepth;
786 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
789 else
791 if (infoPtr->dwStyle & TBS_TOP)
793 /* rectangular part */
794 thumb.top += PointDepth;
795 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_BOTTOM | BF_RIGHT | BF_SOFT);
797 /* light edge */
798 thumb.left = infoPtr->rcThumb.left;
799 thumb.right = thumb.left + PointDepth;
800 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
801 thumb.top -= PointDepth;
802 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
804 /* shadowed edge */
805 thumb.left += PointDepth;
806 thumb.right += PointDepth;
807 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMRIGHT | BF_SOFT);
809 else
811 /* rectangular part */
812 thumb.bottom -= PointDepth;
813 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT);
815 /* light edge */
816 thumb.left = infoPtr->rcThumb.left;
817 thumb.right = thumb.left + PointDepth;
818 thumb.top = infoPtr->rcThumb.bottom - PointDepth - 1;
819 thumb.bottom += PointDepth;
820 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
822 /* shadowed edge */
823 thumb.left += PointDepth;
824 thumb.right += PointDepth;
825 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
832 static inline void
833 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
835 TTTOOLINFOW ti;
837 if (!infoPtr->hwndToolTip) return;
839 ZeroMemory(&ti, sizeof(ti));
840 ti.cbSize = sizeof(ti);
841 ti.hwnd = infoPtr->hwndSelf;
843 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
847 static void
848 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
850 WCHAR buf[80];
851 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
852 TTTOOLINFOW ti;
853 POINT pt;
854 RECT rcClient;
855 LRESULT size;
857 if (!infoPtr->hwndToolTip) return;
859 ZeroMemory(&ti, sizeof(ti));
860 ti.cbSize = sizeof(ti);
861 ti.hwnd = infoPtr->hwndSelf;
862 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
864 wsprintfW (buf, fmt, infoPtr->lPos);
865 ti.lpszText = buf;
866 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
868 GetClientRect (infoPtr->hwndSelf, &rcClient);
869 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
870 if (infoPtr->dwStyle & TBS_VERT) {
871 if (infoPtr->fLocation == TBTS_LEFT)
872 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
873 else
874 pt.x = rcClient.right + TOOLTIP_OFFSET;
875 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
876 } else {
877 if (infoPtr->fLocation == TBTS_TOP)
878 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
879 else
880 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
881 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
883 ClientToScreen(infoPtr->hwndSelf, &pt);
885 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
886 0, MAKELPARAM(pt.x, pt.y));
890 static void
891 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
893 RECT rcClient;
894 HDC hdc;
895 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
896 NMCUSTOMDRAW nmcd;
897 int gcdrf, icdrf;
899 if (infoPtr->flags & TB_THUMBCHANGED) {
900 TRACKBAR_UpdateThumb (infoPtr);
901 if (infoPtr->flags & TB_THUMBSIZECHANGED)
902 TRACKBAR_CalcChannel (infoPtr);
904 if (infoPtr->flags & TB_SELECTIONCHANGED)
905 TRACKBAR_CalcSelection (infoPtr);
907 if (infoPtr->flags & TB_DRAG_MODE)
908 TRACKBAR_UpdateToolTip (infoPtr);
910 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
912 GetClientRect (infoPtr->hwndSelf, &rcClient);
914 /* try to render offscreen, if we fail, carrry onscreen */
915 hdc = CreateCompatibleDC(hdcDst);
916 if (hdc) {
917 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
918 if (hOffScreenBmp) {
919 hOldBmp = SelectObject(hdc, hOffScreenBmp);
920 } else {
921 DeleteObject(hdc);
922 hdc = hdcDst;
924 } else {
925 hdc = hdcDst;
928 ZeroMemory(&nmcd, sizeof(nmcd));
929 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
930 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
931 nmcd.hdr.code = NM_CUSTOMDRAW;
932 nmcd.hdc = hdc;
934 /* start the paint cycle */
935 nmcd.rc = rcClient;
936 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
937 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
939 /* Erase background */
940 if (gcdrf == CDRF_DODEFAULT ||
941 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
942 if (GetWindowTheme (infoPtr->hwndSelf)) {
943 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
945 else {
946 HBRUSH brush = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLORSTATIC,
947 (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
948 FillRect (hdc, &rcClient, brush ? brush : GetSysColorBrush(COLOR_BTNFACE));
950 if (gcdrf != CDRF_DODEFAULT)
951 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
954 /* draw channel */
955 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
956 nmcd.dwItemSpec = TBCD_CHANNEL;
957 nmcd.uItemState = CDIS_DEFAULT;
958 nmcd.rc = infoPtr->rcChannel;
959 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
960 } else icdrf = CDRF_DODEFAULT;
961 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
962 TRACKBAR_DrawChannel (infoPtr, hdc);
963 if (icdrf & CDRF_NOTIFYPOSTPAINT)
964 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
968 /* draw tics */
969 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
970 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
971 nmcd.dwItemSpec = TBCD_TICS;
972 nmcd.uItemState = CDIS_DEFAULT;
973 nmcd.rc = rcClient;
974 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
975 } else icdrf = CDRF_DODEFAULT;
976 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
977 TRACKBAR_DrawTics (infoPtr, hdc);
978 if (icdrf & CDRF_NOTIFYPOSTPAINT)
979 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
983 /* draw thumb */
984 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
985 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
986 nmcd.dwItemSpec = TBCD_THUMB;
987 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
988 nmcd.rc = infoPtr->rcThumb;
989 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
990 } else icdrf = CDRF_DODEFAULT;
991 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
992 TRACKBAR_DrawThumb(infoPtr, hdc);
993 if (icdrf & CDRF_NOTIFYPOSTPAINT)
994 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
998 /* draw focus rectangle */
999 if (infoPtr->bFocussed) {
1000 DrawFocusRect(hdc, &rcClient);
1003 /* finish up the painting */
1004 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
1005 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
1007 cleanup:
1008 /* cleanup, if we rendered offscreen */
1009 if (hdc != hdcDst) {
1010 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
1011 SelectObject(hdc, hOldBmp);
1012 DeleteObject(hOffScreenBmp);
1013 DeleteObject(hdc);
1018 static void
1019 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
1021 HWND hwndParent = GetParent (infoPtr->hwndSelf);
1022 RECT rcSelf, rcBuddy;
1023 INT x, y;
1025 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
1026 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
1028 /* align buddy left or above */
1029 if (infoPtr->hwndBuddyLA) {
1030 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
1031 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1033 if (infoPtr->dwStyle & TBS_VERT) {
1034 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1035 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1036 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
1038 else {
1039 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
1040 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1041 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1044 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
1045 SWP_NOZORDER | SWP_NOSIZE);
1049 /* align buddy right or below */
1050 if (infoPtr->hwndBuddyRB) {
1051 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
1052 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1054 if (infoPtr->dwStyle & TBS_VERT) {
1055 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1056 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1057 y = rcSelf.bottom;
1059 else {
1060 x = rcSelf.right;
1061 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1062 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1064 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
1065 SWP_NOZORDER | SWP_NOSIZE);
1070 static LRESULT
1071 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1073 infoPtr->lSelMin = 0;
1074 infoPtr->lSelMax = 0;
1075 infoPtr->flags |= TB_SELECTIONCHANGED;
1077 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1079 return 0;
1083 static LRESULT
1084 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1086 if (infoPtr->tics) {
1087 Free (infoPtr->tics);
1088 infoPtr->tics = NULL;
1089 infoPtr->uNumTics = 0;
1092 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1094 return 0;
1098 static inline LRESULT
1099 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1101 if (lprc == NULL) return 0;
1103 lprc->left = infoPtr->rcChannel.left;
1104 lprc->right = infoPtr->rcChannel.right;
1105 lprc->bottom = infoPtr->rcChannel.bottom;
1106 lprc->top = infoPtr->rcChannel.top;
1108 return 0;
1112 static inline LONG
1113 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1115 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1117 return infoPtr->uNumTics + 2;
1121 static int comp_tics (const void *ap, const void *bp)
1123 const DWORD a = *(const DWORD *)ap;
1124 const DWORD b = *(const DWORD *)bp;
1126 TRACE("(a=%d, b=%d)\n", a, b);
1127 if (a < b) return -1;
1128 if (a > b) return 1;
1129 return 0;
1133 static inline LONG
1134 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1136 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1137 return -1;
1139 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1140 return infoPtr->tics[iTic];
1144 static inline LONG
1145 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1147 LONG range, width, pos, tic;
1148 int offsetthumb;
1150 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1151 return -1;
1153 tic = TRACKBAR_GetTic (infoPtr, iTic);
1154 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1155 if (range <= 0) range = 1;
1156 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1157 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1158 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1160 return pos;
1164 static HWND
1165 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1167 HWND hwndTemp;
1169 if (fLocation) {
1170 /* buddy is left or above */
1171 hwndTemp = infoPtr->hwndBuddyLA;
1172 infoPtr->hwndBuddyLA = hwndBuddy;
1174 else {
1175 /* buddy is right or below */
1176 hwndTemp = infoPtr->hwndBuddyRB;
1177 infoPtr->hwndBuddyRB = hwndBuddy;
1180 TRACKBAR_AlignBuddies (infoPtr);
1182 return hwndTemp;
1186 static inline LONG
1187 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1189 LONG lTemp = infoPtr->lLineSize;
1191 infoPtr->lLineSize = lLineSize;
1193 return lTemp;
1197 static inline LONG
1198 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1200 LONG lTemp = infoPtr->lPageSize;
1202 if (lPageSize != -1)
1203 infoPtr->lPageSize = lPageSize;
1204 else
1205 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1207 return lTemp;
1211 static inline LRESULT
1212 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1214 LONG oldPos = infoPtr->lPos;
1215 infoPtr->lPos = lPosition;
1217 if (infoPtr->lPos < infoPtr->lRangeMin)
1218 infoPtr->lPos = infoPtr->lRangeMin;
1220 if (infoPtr->lPos > infoPtr->lRangeMax)
1221 infoPtr->lPos = infoPtr->lRangeMax;
1223 if (fPosition && oldPos != lPosition)
1225 TRACKBAR_UpdateThumb(infoPtr);
1226 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1229 return 0;
1233 static inline LRESULT
1234 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
1236 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1237 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1239 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1240 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1242 /* clip position to new min/max limit */
1243 if (infoPtr->lPos < infoPtr->lRangeMin)
1244 infoPtr->lPos = infoPtr->lRangeMin;
1246 if (infoPtr->lPos > infoPtr->lRangeMax)
1247 infoPtr->lPos = infoPtr->lRangeMax;
1249 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1250 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1252 if (changed) {
1253 if (infoPtr->dwStyle & TBS_AUTOTICKS)
1254 TRACKBAR_RecalculateTics (infoPtr);
1255 infoPtr->flags |= TB_THUMBPOSCHANGED;
1258 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1260 return 0;
1264 static inline LRESULT
1265 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1267 BOOL changed = infoPtr->lRangeMax != lMax;
1268 LONG rightmost = max(lMax, infoPtr->lRangeMin);
1270 infoPtr->lRangeMax = lMax;
1271 if (infoPtr->lPos > rightmost) {
1272 infoPtr->lPos = rightmost;
1273 infoPtr->flags |= TB_THUMBPOSCHANGED;
1276 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1277 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1279 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1280 TRACKBAR_RecalculateTics (infoPtr);
1282 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1284 return 0;
1288 static inline LRESULT
1289 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1291 BOOL changed = infoPtr->lRangeMin != lMin;
1293 infoPtr->lRangeMin = lMin;
1294 if (infoPtr->lPos < infoPtr->lRangeMin) {
1295 infoPtr->lPos = infoPtr->lRangeMin;
1296 infoPtr->flags |= TB_THUMBPOSCHANGED;
1299 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1300 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1302 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1303 TRACKBAR_RecalculateTics (infoPtr);
1305 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1307 return 0;
1311 static inline LRESULT
1312 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1314 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1315 infoPtr->lSelMin = 0;
1316 infoPtr->lSelMax = 0;
1317 return 0;
1320 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1321 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1322 infoPtr->flags |= TB_SELECTIONCHANGED;
1324 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1325 infoPtr->lSelMin = infoPtr->lRangeMin;
1326 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1327 infoPtr->lSelMax = infoPtr->lRangeMax;
1329 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1331 return 0;
1335 static inline LRESULT
1336 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1338 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1339 infoPtr->lSelMax = 0;
1340 return 0;
1343 infoPtr->lSelMax = lEnd;
1344 infoPtr->flags |= TB_SELECTIONCHANGED;
1346 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1347 infoPtr->lSelMax = infoPtr->lRangeMax;
1349 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1351 return 0;
1355 static inline LRESULT
1356 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1358 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1359 infoPtr->lSelMin = 0;
1360 return 0;
1363 infoPtr->lSelMin = lStart;
1364 infoPtr->flags |=TB_SELECTIONCHANGED;
1366 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1367 infoPtr->lSelMin = infoPtr->lRangeMin;
1369 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1371 return 0;
1375 static inline LRESULT
1376 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1378 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1379 /* We're not supposed to check if it's really changed or not,
1380 just repaint in any case. */
1381 infoPtr->uThumbLen = iLength;
1382 infoPtr->flags |= TB_THUMBSIZECHANGED;
1383 TRACKBAR_InvalidateAll(infoPtr);
1386 return 0;
1390 static inline LRESULT
1391 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1393 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1394 return FALSE;
1396 TRACE("lPos=%d\n", lPos);
1398 infoPtr->uNumTics++;
1399 infoPtr->tics=ReAlloc( infoPtr->tics,
1400 (infoPtr->uNumTics)*sizeof (DWORD));
1401 if (!infoPtr->tics) {
1402 infoPtr->uNumTics = 0;
1403 notify(infoPtr, NM_OUTOFMEMORY);
1404 return FALSE;
1406 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1408 TRACKBAR_InvalidateAll(infoPtr);
1410 return TRUE;
1414 static inline LRESULT
1415 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1417 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1418 infoPtr->uTicFreq = wFreq;
1419 TRACKBAR_RecalculateTics (infoPtr);
1420 TRACKBAR_InvalidateAll(infoPtr);
1423 TRACKBAR_UpdateThumb (infoPtr);
1424 return 0;
1428 static inline INT
1429 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1431 INT fTemp = infoPtr->fLocation;
1433 infoPtr->fLocation = fLocation;
1435 return fTemp;
1439 static inline LRESULT
1440 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1442 infoPtr->hwndToolTip = hwndTT;
1444 return 0;
1448 static inline BOOL
1449 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1451 BOOL bTemp = infoPtr->bUnicode;
1453 infoPtr->bUnicode = fUnicode;
1455 return bTemp;
1459 static LRESULT
1460 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1462 RECT rect;
1463 int clientWidth, clientMetric;
1465 /* initial thumb length */
1466 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1467 GetClientRect(infoPtr->hwndSelf,&rect);
1468 if (infoPtr->dwStyle & TBS_VERT) {
1469 clientWidth = rect.right - rect.left;
1470 } else {
1471 clientWidth = rect.bottom - rect.top;
1473 if (clientWidth >= clientMetric)
1474 infoPtr->uThumbLen = clientMetric;
1475 else
1476 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1478 TRACKBAR_CalcChannel (infoPtr);
1479 TRACKBAR_UpdateThumb (infoPtr);
1480 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1482 return 0;
1486 static LRESULT
1487 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1489 TRACKBAR_INFO *infoPtr;
1491 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1492 if (!infoPtr) return -1;
1493 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1495 /* set default values */
1496 infoPtr->hwndSelf = hwnd;
1497 infoPtr->dwStyle = lpcs->style;
1498 infoPtr->lRangeMin = 0;
1499 infoPtr->lRangeMax = 100;
1500 infoPtr->lLineSize = 1;
1501 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1502 infoPtr->lSelMin = 0;
1503 infoPtr->lSelMax = 0;
1504 infoPtr->lPos = 0;
1505 infoPtr->fLocation = TBTS_TOP;
1506 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1507 infoPtr->uTicFreq = 1;
1508 infoPtr->tics = NULL;
1509 infoPtr->hwndNotify= lpcs->hwndParent;
1511 TRACKBAR_InitializeThumb (infoPtr);
1513 /* Create tooltip control */
1514 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1516 infoPtr->hwndToolTip =
1517 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1518 CW_USEDEFAULT, CW_USEDEFAULT,
1519 CW_USEDEFAULT, CW_USEDEFAULT,
1520 hwnd, 0, 0, 0);
1522 if (infoPtr->hwndToolTip) {
1523 TTTOOLINFOW ti;
1524 WCHAR wEmpty = 0;
1525 ZeroMemory (&ti, sizeof(ti));
1526 ti.cbSize = sizeof(ti);
1527 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1528 ti.hwnd = hwnd;
1529 ti.lpszText = &wEmpty;
1531 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1535 OpenThemeData (hwnd, themeClass);
1537 return 0;
1541 static LRESULT
1542 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1544 /* delete tooltip control */
1545 if (infoPtr->hwndToolTip)
1546 DestroyWindow (infoPtr->hwndToolTip);
1548 Free (infoPtr->tics);
1549 infoPtr->tics = NULL;
1551 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1552 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1553 Free (infoPtr);
1555 return 0;
1559 static LRESULT
1560 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1562 TRACE("\n");
1563 infoPtr->bFocussed = FALSE;
1564 TRACKBAR_InvalidateAll(infoPtr);
1566 return 0;
1569 static LRESULT
1570 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1572 POINT clickPoint;
1574 clickPoint.x = x;
1575 clickPoint.y = y;
1577 SetFocus(infoPtr->hwndSelf);
1579 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1580 infoPtr->flags |= TB_DRAG_MODE;
1581 SetCapture (infoPtr->hwndSelf);
1582 TRACKBAR_UpdateToolTip (infoPtr);
1583 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1584 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1585 } else {
1586 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1587 if (dir == 0) return 0;
1588 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1589 TRACKBAR_AutoPage (infoPtr, clickPoint);
1590 SetCapture (infoPtr->hwndSelf);
1591 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1594 return 0;
1598 static LRESULT
1599 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1601 if (infoPtr->flags & TB_DRAG_MODE) {
1602 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1603 notify_with_scroll (infoPtr, TB_ENDTRACK);
1604 infoPtr->flags &= ~TB_DRAG_MODE;
1605 ReleaseCapture ();
1606 notify(infoPtr, NM_RELEASEDCAPTURE);
1607 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1608 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1610 if (infoPtr->flags & TB_AUTO_PAGE) {
1611 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1612 infoPtr->flags &= ~TB_AUTO_PAGE;
1613 notify_with_scroll (infoPtr, TB_ENDTRACK);
1614 ReleaseCapture ();
1615 notify(infoPtr, NM_RELEASEDCAPTURE);
1618 return 0;
1622 static LRESULT
1623 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1625 notify_with_scroll (infoPtr, TB_ENDTRACK);
1626 return 0;
1630 static LRESULT
1631 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1633 if (hdc) {
1634 TRACKBAR_Refresh(infoPtr, hdc);
1635 } else {
1636 PAINTSTRUCT ps;
1637 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1638 TRACKBAR_Refresh (infoPtr, hdc);
1639 EndPaint (infoPtr->hwndSelf, &ps);
1642 return 0;
1646 static LRESULT
1647 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1649 TRACE("\n");
1650 infoPtr->bFocussed = TRUE;
1651 TRACKBAR_InvalidateAll(infoPtr);
1653 return 0;
1657 static LRESULT
1658 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1660 if (infoPtr->dwStyle & TBS_FIXEDLENGTH)
1662 TRACKBAR_CalcChannel(infoPtr);
1663 TRACKBAR_UpdateThumb(infoPtr);
1665 else
1666 TRACKBAR_InitializeThumb(infoPtr);
1667 TRACKBAR_AlignBuddies (infoPtr);
1668 TRACKBAR_InvalidateAll(infoPtr);
1670 return 0;
1673 static LRESULT
1674 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1675 const STYLESTRUCT *lpss)
1677 if (wStyleType != GWL_STYLE) return 0;
1679 infoPtr->dwStyle = lpss->styleNew;
1681 return 0;
1684 static LRESULT
1685 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1687 if (infoPtr->flags & TB_AUTO_PAGE) {
1688 POINT pt;
1689 if (GetCursorPos(&pt))
1690 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1691 TRACKBAR_AutoPage(infoPtr, pt);
1693 return 0;
1697 /* update theme after a WM_THEMECHANGED message */
1698 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1700 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1701 CloseThemeData (theme);
1702 OpenThemeData (infoPtr->hwndSelf, themeClass);
1703 return 0;
1707 static LRESULT
1708 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1710 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1711 LONG dragPos, oldPos = infoPtr->lPos;
1713 TRACE("(x=%d. y=%d)\n", x, y);
1715 if (infoPtr->flags & TB_AUTO_PAGE) {
1716 POINT pt;
1717 pt.x = x;
1718 pt.y = y;
1719 TRACKBAR_AutoPage (infoPtr, pt);
1720 return TRUE;
1723 if (!(infoPtr->flags & TB_DRAG_MODE))
1725 if (GetWindowTheme (infoPtr->hwndSelf))
1727 DWORD oldFlags = infoPtr->flags;
1728 POINT pt;
1729 pt.x = x;
1730 pt.y = y;
1731 if (PtInRect (&infoPtr->rcThumb, pt))
1733 TRACKMOUSEEVENT tme;
1734 tme.cbSize = sizeof( tme );
1735 tme.dwFlags = TME_LEAVE;
1736 tme.hwndTrack = infoPtr->hwndSelf;
1737 TrackMouseEvent( &tme );
1738 infoPtr->flags |= TB_THUMB_HOT;
1740 else
1742 TRACKMOUSEEVENT tme;
1743 tme.cbSize = sizeof( tme );
1744 tme.dwFlags = TME_CANCEL;
1745 tme.hwndTrack = infoPtr->hwndSelf;
1746 TrackMouseEvent( &tme );
1747 infoPtr->flags &= ~TB_THUMB_HOT;
1749 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1751 return TRUE;
1754 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1756 if (dragPos == oldPos) return TRUE;
1758 infoPtr->lPos = dragPos;
1759 TRACKBAR_UpdateThumb (infoPtr);
1761 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1763 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1764 UpdateWindow (infoPtr->hwndSelf);
1766 return TRUE;
1769 static BOOL
1770 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1772 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1773 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1774 LONG pos = infoPtr->lPos;
1776 TRACE("%x\n", nVirtKey);
1778 switch (nVirtKey) {
1779 case VK_UP:
1780 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1781 else TRACKBAR_LineUp(infoPtr);
1782 break;
1783 case VK_LEFT:
1784 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1785 else TRACKBAR_LineUp(infoPtr);
1786 break;
1787 case VK_DOWN:
1788 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1789 else TRACKBAR_LineDown(infoPtr);
1790 break;
1791 case VK_RIGHT:
1792 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1793 else TRACKBAR_LineDown(infoPtr);
1794 break;
1795 case VK_NEXT:
1796 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1797 else TRACKBAR_PageDown(infoPtr);
1798 break;
1799 case VK_PRIOR:
1800 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1801 else TRACKBAR_PageUp(infoPtr);
1802 break;
1803 case VK_HOME:
1804 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1805 infoPtr->lPos = infoPtr->lRangeMin;
1806 notify_with_scroll (infoPtr, TB_TOP);
1807 break;
1808 case VK_END:
1809 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1810 infoPtr->lPos = infoPtr->lRangeMax;
1811 notify_with_scroll (infoPtr, TB_BOTTOM);
1812 break;
1815 if (pos != infoPtr->lPos) {
1816 TRACKBAR_UpdateThumb (infoPtr);
1817 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1820 return TRUE;
1824 static inline BOOL
1825 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1827 switch (nVirtKey) {
1828 case VK_LEFT:
1829 case VK_UP:
1830 case VK_RIGHT:
1831 case VK_DOWN:
1832 case VK_NEXT:
1833 case VK_PRIOR:
1834 case VK_HOME:
1835 case VK_END:
1836 notify_with_scroll (infoPtr, TB_ENDTRACK);
1838 return TRUE;
1842 static LRESULT
1843 TRACKBAR_Enable (TRACKBAR_INFO *infoPtr, BOOL enable)
1845 if (enable)
1846 infoPtr->dwStyle &= ~WS_DISABLED;
1847 else
1848 infoPtr->dwStyle |= WS_DISABLED;
1850 InvalidateRect(infoPtr->hwndSelf, &infoPtr->rcThumb, TRUE);
1852 return 1;
1855 static LRESULT WINAPI
1856 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1858 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1860 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1862 if (!infoPtr && (uMsg != WM_CREATE))
1863 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1865 switch (uMsg)
1867 case TBM_CLEARSEL:
1868 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1870 case TBM_CLEARTICS:
1871 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1873 case TBM_GETBUDDY:
1874 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1876 case TBM_GETCHANNELRECT:
1877 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1879 case TBM_GETLINESIZE:
1880 return infoPtr->lLineSize;
1882 case TBM_GETNUMTICS:
1883 return TRACKBAR_GetNumTics (infoPtr);
1885 case TBM_GETPAGESIZE:
1886 return infoPtr->lPageSize;
1888 case TBM_GETPOS:
1889 return infoPtr->lPos;
1891 case TBM_GETPTICS:
1892 return (LRESULT)infoPtr->tics;
1894 case TBM_GETRANGEMAX:
1895 return infoPtr->lRangeMax;
1897 case TBM_GETRANGEMIN:
1898 return infoPtr->lRangeMin;
1900 case TBM_GETSELEND:
1901 return infoPtr->lSelMax;
1903 case TBM_GETSELSTART:
1904 return infoPtr->lSelMin;
1906 case TBM_GETTHUMBLENGTH:
1907 return infoPtr->uThumbLen;
1909 case TBM_GETTHUMBRECT:
1910 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1912 case TBM_GETTIC:
1913 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1915 case TBM_GETTICPOS:
1916 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1918 case TBM_GETTOOLTIPS:
1919 return (LRESULT)infoPtr->hwndToolTip;
1921 case TBM_GETUNICODEFORMAT:
1922 return infoPtr->bUnicode;
1924 case TBM_SETBUDDY:
1925 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1927 case TBM_SETLINESIZE:
1928 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1930 case TBM_SETPAGESIZE:
1931 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1933 case TBM_SETPOS:
1934 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1936 case TBM_SETRANGE:
1937 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1939 case TBM_SETRANGEMAX:
1940 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1942 case TBM_SETRANGEMIN:
1943 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1945 case TBM_SETSEL:
1946 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1948 case TBM_SETSELEND:
1949 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1951 case TBM_SETSELSTART:
1952 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1954 case TBM_SETTHUMBLENGTH:
1955 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1957 case TBM_SETTIC:
1958 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1960 case TBM_SETTICFREQ:
1961 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1963 case TBM_SETTIPSIDE:
1964 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1966 case TBM_SETTOOLTIPS:
1967 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1969 case TBM_SETUNICODEFORMAT:
1970 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1973 case WM_CAPTURECHANGED:
1974 if (hwnd == (HWND)lParam) return 0;
1975 return TRACKBAR_CaptureChanged (infoPtr);
1977 case WM_CREATE:
1978 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1980 case WM_DESTROY:
1981 return TRACKBAR_Destroy (infoPtr);
1983 case WM_ENABLE:
1984 return TRACKBAR_Enable (infoPtr, (BOOL)wParam);
1986 case WM_ERASEBKGND:
1987 return 0;
1989 case WM_GETDLGCODE:
1990 return DLGC_WANTARROWS;
1992 case WM_KEYDOWN:
1993 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
1995 case WM_KEYUP:
1996 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
1998 case WM_KILLFOCUS:
1999 return TRACKBAR_KillFocus (infoPtr);
2001 case WM_LBUTTONDOWN:
2002 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2004 case WM_LBUTTONUP:
2005 return TRACKBAR_LButtonUp (infoPtr);
2007 case WM_MOUSELEAVE:
2008 infoPtr->flags &= ~TB_THUMB_HOT;
2009 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
2010 return 0;
2012 case WM_MOUSEMOVE:
2013 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2015 case WM_PRINTCLIENT:
2016 case WM_PAINT:
2017 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
2019 case WM_SETFOCUS:
2020 return TRACKBAR_SetFocus (infoPtr);
2022 case WM_SIZE:
2023 return TRACKBAR_Size (infoPtr);
2025 case WM_STYLECHANGED:
2026 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2028 case WM_THEMECHANGED:
2029 return theme_changed (infoPtr);
2031 case WM_TIMER:
2032 return TRACKBAR_Timer (infoPtr);
2034 case WM_WININICHANGE:
2035 return TRACKBAR_InitializeThumb (infoPtr);
2037 default:
2038 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2039 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2040 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2045 void TRACKBAR_Register (void)
2047 WNDCLASSW wndClass;
2049 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2050 wndClass.style = CS_GLOBALCLASS;
2051 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
2052 wndClass.cbClsExtra = 0;
2053 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
2054 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2055 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2056 wndClass.lpszClassName = TRACKBAR_CLASSW;
2058 RegisterClassW (&wndClass);
2062 void TRACKBAR_Unregister (void)
2064 UnregisterClassW (TRACKBAR_CLASSW, NULL);