wined3d: Fix missing break inside switch in SetAutoGenFilterType.
[wine.git] / dlls / comctl32 / trackbar.c
blobe81d55f2ec70ad6485d124d166c2e7520609d5ed
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 "tmschema.h"
46 #include "wine/debug.h"
48 #include "comctl32.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
52 typedef struct
54 HWND hwndSelf;
55 LONG lRangeMin;
56 LONG lRangeMax;
57 LONG lLineSize;
58 LONG lPageSize;
59 LONG lSelMin;
60 LONG lSelMax;
61 LONG lPos;
62 UINT uThumbLen;
63 UINT uNumTics;
64 UINT uTicFreq;
65 HWND hwndNotify;
66 HWND hwndToolTip;
67 HWND hwndBuddyLA;
68 HWND hwndBuddyRB;
69 INT fLocation;
70 INT flags;
71 BOOL bUnicode;
72 BOOL bFocussed;
73 RECT rcChannel;
74 RECT rcSelection;
75 RECT rcThumb;
76 LPLONG tics;
77 } TRACKBAR_INFO;
79 #define TB_REFRESH_TIMER 1
80 #define TB_REFRESH_DELAY 500
82 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
84 /* Used by TRACKBAR_Refresh to find out which parts of the control
85 need to be recalculated */
87 #define TB_THUMBPOSCHANGED 1
88 #define TB_THUMBSIZECHANGED 2
89 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
90 #define TB_SELECTIONCHANGED 4
91 #define TB_DRAG_MODE 8 /* we're dragging the slider */
92 #define TB_AUTO_PAGE_LEFT 16
93 #define TB_AUTO_PAGE_RIGHT 32
94 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
95 #define TB_THUMB_HOT 64 /* mouse hovers above thumb */
97 /* helper defines for TRACKBAR_DrawTic */
98 #define TIC_EDGE 0x20
99 #define TIC_SELECTIONMARKMAX 0x80
100 #define TIC_SELECTIONMARKMIN 0x100
101 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
103 static const WCHAR themeClass[] = { 'T','r','a','c','k','b','a','r',0 };
105 static inline int
106 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
108 pnmcd->dwDrawStage = stage;
109 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
110 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
113 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
115 LRESULT result;
117 TRACE("(code=%d)\n", code);
119 pnmh->hwndFrom = infoPtr->hwndSelf;
120 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
121 pnmh->code = code;
122 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
124 TRACE(" <= %ld\n", result);
126 return result;
129 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
131 NMHDR nmh;
132 return notify_hdr(infoPtr, code, &nmh);
135 static BOOL
136 notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
138 BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT;
140 TRACE("%x\n", code);
142 return (BOOL) SendMessageW (infoPtr->hwndNotify,
143 bVert ? WM_VSCROLL : WM_HSCROLL,
144 (WPARAM)code, (LPARAM)infoPtr->hwndSelf);
147 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
149 int i, tic, nrTics;
151 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin)
152 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
153 else {
154 nrTics = 0;
155 Free (infoPtr->tics);
156 infoPtr->tics = NULL;
157 infoPtr->uNumTics = 0;
158 return;
161 if (nrTics != infoPtr->uNumTics) {
162 infoPtr->tics=ReAlloc (infoPtr->tics,
163 (nrTics+1)*sizeof (DWORD));
164 if (!infoPtr->tics) {
165 infoPtr->uNumTics = 0;
166 notify(infoPtr, NM_OUTOFMEMORY);
167 return;
169 infoPtr->uNumTics = nrTics;
172 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
173 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
174 infoPtr->tics[i] = tic;
177 /* converts from physical (mouse) position to logical position
178 (in range of trackbar) */
180 static inline LONG
181 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place, int vertical)
183 double range, width, pos, offsetthumb;
185 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
186 if (vertical) {
187 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
188 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
189 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
190 } else {
191 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
192 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
193 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
195 pos += infoPtr->lRangeMin;
196 if (pos > infoPtr->lRangeMax)
197 pos = infoPtr->lRangeMax;
198 else if (pos < infoPtr->lRangeMin)
199 pos = infoPtr->lRangeMin;
201 TRACE("%.2f\n", pos);
202 return (LONG)(pos + 0.5);
206 /* return: 0> prev, 0 none, >0 next */
207 static LONG
208 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
210 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
211 RECT pageRect;
213 if (dwStyle & TBS_VERT) {
214 pageRect.top = infoPtr->rcChannel.top;
215 pageRect.bottom = infoPtr->rcChannel.bottom;
216 pageRect.left = infoPtr->rcThumb.left;
217 pageRect.right = infoPtr->rcThumb.right;
218 } else {
219 pageRect.top = infoPtr->rcThumb.top;
220 pageRect.bottom = infoPtr->rcThumb.bottom;
221 pageRect.left = infoPtr->rcChannel.left;
222 pageRect.right = infoPtr->rcChannel.right;
226 if (PtInRect(&pageRect, clickPoint))
228 int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
230 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace,
231 dwStyle & TBS_VERT);
232 return clickPos - infoPtr->lPos;
235 return 0;
238 static inline void
239 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
241 if (infoPtr->lPos == infoPtr->lRangeMax) return;
243 infoPtr->lPos += infoPtr->lPageSize;
244 if (infoPtr->lPos > infoPtr->lRangeMax)
245 infoPtr->lPos = infoPtr->lRangeMax;
246 notify_with_scroll (infoPtr, TB_PAGEDOWN);
250 static inline void
251 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
253 if (infoPtr->lPos == infoPtr->lRangeMin) return;
255 infoPtr->lPos -= infoPtr->lPageSize;
256 if (infoPtr->lPos < infoPtr->lRangeMin)
257 infoPtr->lPos = infoPtr->lRangeMin;
258 notify_with_scroll (infoPtr, TB_PAGEUP);
261 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
263 if (infoPtr->lPos == infoPtr->lRangeMin) return;
264 infoPtr->lPos -= infoPtr->lLineSize;
265 if (infoPtr->lPos < infoPtr->lRangeMin)
266 infoPtr->lPos = infoPtr->lRangeMin;
267 notify_with_scroll (infoPtr, TB_LINEUP);
270 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
272 if (infoPtr->lPos == infoPtr->lRangeMax) return;
273 infoPtr->lPos += infoPtr->lLineSize;
274 if (infoPtr->lPos > infoPtr->lRangeMax)
275 infoPtr->lPos = infoPtr->lRangeMax;
276 notify_with_scroll (infoPtr, TB_LINEDOWN);
279 static void
280 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
282 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
283 INT cyChannel, offsetthumb, offsetedge;
284 RECT lpRect, *channel = & infoPtr->rcChannel;
286 GetClientRect (infoPtr->hwndSelf, &lpRect);
288 offsetthumb = infoPtr->uThumbLen / 4;
289 offsetedge = offsetthumb + 3;
290 cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
291 if (dwStyle & TBS_VERT) {
292 channel->top = lpRect.top + offsetedge;
293 channel->bottom = lpRect.bottom - offsetedge;
294 if (dwStyle & TBS_ENABLESELRANGE)
295 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
296 else
297 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
298 if (dwStyle & TBS_BOTH) {
299 if (dwStyle & TBS_NOTICKS)
300 channel->left += 1;
301 else
302 channel->left += 9;
304 else if (dwStyle & TBS_TOP) {
305 if (dwStyle & TBS_NOTICKS)
306 channel->left += 2;
307 else
308 channel->left += 10;
310 channel->right = channel->left + cyChannel;
311 } else {
312 channel->left = lpRect.left + offsetedge;
313 channel->right = lpRect.right - offsetedge;
314 if (dwStyle & TBS_ENABLESELRANGE)
315 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
316 else
317 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
318 if (dwStyle & TBS_BOTH) {
319 if (dwStyle & TBS_NOTICKS)
320 channel->top += 1;
321 else
322 channel->top += 9;
324 else if (dwStyle & TBS_TOP) {
325 if (dwStyle & TBS_NOTICKS)
326 channel->top += 2;
327 else
328 channel->top += 10;
330 channel->bottom = channel->top + cyChannel;
334 static void
335 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
337 int range, width, height, thumbwidth;
338 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
339 RECT lpRect;
341 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
342 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
344 if (!range) range = 1;
346 GetClientRect(infoPtr->hwndSelf, &lpRect);
347 if (dwStyle & TBS_VERT)
349 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
351 if ((dwStyle & (TBS_BOTH | TBS_LEFT)) && !(dwStyle & TBS_NOTICKS))
352 thumb->left = 10;
353 else
354 thumb->left = 2;
355 thumb->right = thumb->left + infoPtr->uThumbLen;
356 thumb->top = infoPtr->rcChannel.top +
357 (height*(lPos - infoPtr->lRangeMin))/range;
358 thumb->bottom = thumb->top + thumbwidth;
360 else
362 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
364 thumb->left = infoPtr->rcChannel.left +
365 (width*(lPos - infoPtr->lRangeMin))/range;
366 thumb->right = thumb->left + thumbwidth;
367 if ((dwStyle & (TBS_BOTH | TBS_TOP)) && !(dwStyle & TBS_NOTICKS))
368 thumb->top = 10;
369 else
370 thumb->top = 2;
371 thumb->bottom = thumb->top + infoPtr->uThumbLen;
375 static inline void
376 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
378 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
381 static inline void
382 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
384 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
387 static void
388 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
390 RECT rcThumb;
392 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
393 InflateRect(&rcThumb, 1, 1);
394 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
397 static inline void
398 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
400 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
401 if (newPos != oldPos)
402 TRACKBAR_InvalidateThumb (infoPtr, newPos);
405 static inline BOOL
406 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
408 return infoPtr->lSelMin != infoPtr->lSelMax;
411 static void
412 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
414 RECT *selection = &infoPtr->rcSelection;
415 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
416 int offsetthumb, height, width;
418 if (range <= 0) {
419 SetRectEmpty (selection);
420 } else {
421 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) {
422 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
423 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
424 selection->top = infoPtr->rcChannel.top + offsetthumb +
425 (height*infoPtr->lSelMin)/range;
426 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
427 (height*infoPtr->lSelMax)/range;
428 selection->left = infoPtr->rcChannel.left + 3;
429 selection->right = infoPtr->rcChannel.right - 3;
430 } else {
431 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
432 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
433 selection->left = infoPtr->rcChannel.left + offsetthumb +
434 (width*infoPtr->lSelMin)/range;
435 selection->right = infoPtr->rcChannel.left + offsetthumb +
436 (width*infoPtr->lSelMax)/range;
437 selection->top = infoPtr->rcChannel.top + 3;
438 selection->bottom = infoPtr->rcChannel.bottom - 3;
442 TRACE("selection[%s]\n", wine_dbgstr_rect(selection));
445 static BOOL
446 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
448 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
449 LONG prevPos = infoPtr->lPos;
451 TRACE("x=%d, y=%d, dir=%d\n", clickPoint.x, clickPoint.y, dir);
453 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
454 TRACKBAR_PageDown(infoPtr);
455 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
456 TRACKBAR_PageUp(infoPtr);
457 else return FALSE;
459 infoPtr->flags |= TB_THUMBPOSCHANGED;
460 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
462 return TRUE;
465 /* Trackbar drawing code. I like my spaghetti done milanese. */
467 static void
468 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
470 RECT rcChannel = infoPtr->rcChannel;
471 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
473 if (theme)
475 DrawThemeBackground (theme, hdc,
476 (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) ?
477 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
479 else
481 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
482 if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
483 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
484 if (TRACKBAR_HasSelection(infoPtr))
485 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
490 static void
491 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
493 int x, y, ox, oy, range, side, indent = 0, len = 3;
494 int offsetthumb;
495 RECT rcTics;
497 if (flags & TBS_VERT) {
498 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
499 rcTics.left = infoPtr->rcThumb.left - 2;
500 rcTics.right = infoPtr->rcThumb.right + 2;
501 rcTics.top = infoPtr->rcChannel.top + offsetthumb + 1;
502 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb;
503 } else {
504 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
505 rcTics.left = infoPtr->rcChannel.left + offsetthumb + 1;
506 rcTics.right = infoPtr->rcChannel.right - offsetthumb;
507 rcTics.top = infoPtr->rcThumb.top - 2;
508 rcTics.bottom = infoPtr->rcThumb.bottom + 2;
511 if (flags & (TBS_TOP | TBS_LEFT)) {
512 x = rcTics.left;
513 y = rcTics.top;
514 side = -1;
515 } else {
516 x = rcTics.right;
517 y = rcTics.bottom;
518 side = 1;
521 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
522 if (range <= 0)
523 range = 1; /* to avoid division by zero */
525 if (flags & TIC_SELECTIONMARK) {
526 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
527 } else if (flags & TIC_EDGE) {
528 len++;
531 if (flags & TBS_VERT) {
532 int height = rcTics.bottom - rcTics.top;
533 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
534 } else {
535 int width = rcTics.right - rcTics.left;
536 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
539 ox = x;
540 oy = y;
541 MoveToEx(hdc, x, y, 0);
542 if (flags & TBS_VERT) x += len * side;
543 else y += len * side;
544 LineTo(hdc, x, y);
546 if (flags & TIC_SELECTIONMARK) {
547 if (flags & TBS_VERT) {
548 x -= side;
549 } else {
550 y -= side;
552 MoveToEx(hdc, x, y, 0);
553 if (flags & TBS_VERT) {
554 y += 2 * indent;
555 } else {
556 x += 2 * indent;
559 LineTo(hdc, x, y);
560 LineTo(hdc, ox, oy);
565 static inline void
566 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
568 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
569 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
571 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
572 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
575 static void
576 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
578 unsigned int i;
579 int ticFlags = dwStyle & 0x0f;
580 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
581 HPEN hOldPen, hTicPen;
582 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
584 if (theme)
586 int part = (dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
587 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
589 /* create the pen to draw the tics with */
590 hTicPen = CreatePenIndirect(&ticPen);
591 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
593 /* actually draw the tics */
594 for (i=0; i<infoPtr->uNumTics; i++)
595 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
597 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
600 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
601 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
602 ticFlags | TIC_SELECTIONMARKMIN);
603 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
604 ticFlags | TIC_SELECTIONMARKMAX);
607 /* clean up the pen, if we created one */
608 if (hTicPen) {
609 SelectObject(hdc, hOldPen);
610 DeleteObject(hTicPen);
614 static void
615 TRACKBAR_DrawThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
617 HBRUSH oldbr;
618 HPEN oldpen;
619 RECT thumb = infoPtr->rcThumb;
620 int BlackUntil = 3;
621 int PointCount = 6;
622 POINT points[6];
623 int fillClr;
624 int PointDepth;
625 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
627 if (theme)
629 int partId;
630 int stateId;
631 if (dwStyle & TBS_BOTH)
632 partId = (dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
633 else if (dwStyle & TBS_LEFT)
634 partId = (dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
635 else
636 partId = (dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
638 if (dwStyle & WS_DISABLED)
639 stateId = TUS_DISABLED;
640 else if (infoPtr->flags & TB_DRAG_MODE)
641 stateId = TUS_PRESSED;
642 else if (infoPtr->flags & TB_THUMB_HOT)
643 stateId = TUS_HOT;
644 else
645 stateId = TUS_NORMAL;
647 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
649 return;
652 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
653 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
654 SetPolyFillMode (hdc, WINDING);
656 if (dwStyle & TBS_BOTH)
658 points[0].x=thumb.right;
659 points[0].y=thumb.top;
660 points[1].x=thumb.right;
661 points[1].y=thumb.bottom;
662 points[2].x=thumb.left;
663 points[2].y=thumb.bottom;
664 points[3].x=thumb.left;
665 points[3].y=thumb.top;
666 points[4].x=points[0].x;
667 points[4].y=points[0].y;
668 PointCount = 5;
669 BlackUntil = 3;
671 else
673 if (dwStyle & TBS_VERT)
675 PointDepth = (thumb.bottom - thumb.top) / 2;
676 if (dwStyle & TBS_LEFT)
678 points[0].x=thumb.right;
679 points[0].y=thumb.top;
680 points[1].x=thumb.right;
681 points[1].y=thumb.bottom;
682 points[2].x=thumb.left + PointDepth;
683 points[2].y=thumb.bottom;
684 points[3].x=thumb.left;
685 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
686 points[4].x=thumb.left + PointDepth;
687 points[4].y=thumb.top;
688 points[5].x=points[0].x;
689 points[5].y=points[0].y;
690 BlackUntil = 4;
692 else
694 points[0].x=thumb.right;
695 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
696 points[1].x=thumb.right - PointDepth;
697 points[1].y=thumb.bottom;
698 points[2].x=thumb.left;
699 points[2].y=thumb.bottom;
700 points[3].x=thumb.left;
701 points[3].y=thumb.top;
702 points[4].x=thumb.right - PointDepth;
703 points[4].y=thumb.top;
704 points[5].x=points[0].x;
705 points[5].y=points[0].y;
708 else
710 PointDepth = (thumb.right - thumb.left) / 2;
711 if (dwStyle & TBS_TOP)
713 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
714 points[0].y=thumb.top;
715 points[1].x=thumb.right;
716 points[1].y=thumb.top + PointDepth;
717 points[2].x=thumb.right;
718 points[2].y=thumb.bottom;
719 points[3].x=thumb.left;
720 points[3].y=thumb.bottom;
721 points[4].x=thumb.left;
722 points[4].y=thumb.top + PointDepth;
723 points[5].x=points[0].x;
724 points[5].y=points[0].y;
725 BlackUntil = 4;
727 else
729 points[0].x=thumb.right;
730 points[0].y=thumb.top;
731 points[1].x=thumb.right;
732 points[1].y=thumb.bottom - PointDepth;
733 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
734 points[2].y=thumb.bottom;
735 points[3].x=thumb.left;
736 points[3].y=thumb.bottom - PointDepth;
737 points[4].x=thumb.left;
738 points[4].y=thumb.top;
739 points[5].x=points[0].x;
740 points[5].y=points[0].y;
746 /* Draw the thumb now */
747 Polygon (hdc, points, PointCount);
748 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
749 Polyline(hdc,points, BlackUntil);
750 SelectObject(hdc, GetStockObject(WHITE_PEN));
751 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
752 SelectObject(hdc, oldpen);
753 SelectObject(hdc, oldbr);
757 static inline void
758 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
760 TTTOOLINFOW ti;
762 if (!infoPtr->hwndToolTip) return;
764 ZeroMemory(&ti, sizeof(ti));
765 ti.cbSize = sizeof(ti);
766 ti.hwnd = infoPtr->hwndSelf;
768 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
772 static void
773 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
775 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
776 WCHAR buf[80];
777 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
778 TTTOOLINFOW ti;
779 POINT pt;
780 RECT rcClient;
781 LRESULT size;
783 if (!infoPtr->hwndToolTip) return;
785 ZeroMemory(&ti, sizeof(ti));
786 ti.cbSize = sizeof(ti);
787 ti.hwnd = infoPtr->hwndSelf;
788 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
790 wsprintfW (buf, fmt, infoPtr->lPos);
791 ti.lpszText = buf;
792 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
794 GetClientRect (infoPtr->hwndSelf, &rcClient);
795 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
796 if (dwStyle & TBS_VERT) {
797 if (infoPtr->fLocation == TBTS_LEFT)
798 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
799 else
800 pt.x = rcClient.right + TOOLTIP_OFFSET;
801 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
802 } else {
803 if (infoPtr->fLocation == TBTS_TOP)
804 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
805 else
806 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
807 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
809 ClientToScreen(infoPtr->hwndSelf, &pt);
811 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
812 0, MAKELPARAM(pt.x, pt.y));
816 static void
817 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
819 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
820 RECT rcClient;
821 HDC hdc;
822 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
823 NMCUSTOMDRAW nmcd;
824 int gcdrf, icdrf;
826 if (infoPtr->flags & TB_THUMBCHANGED) {
827 TRACKBAR_UpdateThumb (infoPtr);
828 if (infoPtr->flags & TB_THUMBSIZECHANGED)
829 TRACKBAR_CalcChannel (infoPtr);
831 if (infoPtr->flags & TB_SELECTIONCHANGED)
832 TRACKBAR_CalcSelection (infoPtr);
834 if (infoPtr->flags & TB_DRAG_MODE)
835 TRACKBAR_UpdateToolTip (infoPtr);
837 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
839 GetClientRect (infoPtr->hwndSelf, &rcClient);
841 /* try to render offscreen, if we fail, carrry onscreen */
842 hdc = CreateCompatibleDC(hdcDst);
843 if (hdc) {
844 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
845 if (hOffScreenBmp) {
846 hOldBmp = SelectObject(hdc, hOffScreenBmp);
847 } else {
848 DeleteObject(hdc);
849 hdc = hdcDst;
851 } else {
852 hdc = hdcDst;
855 ZeroMemory(&nmcd, sizeof(nmcd));
856 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
857 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
858 nmcd.hdr.code = NM_CUSTOMDRAW;
859 nmcd.hdc = hdc;
861 /* start the paint cycle */
862 nmcd.rc = rcClient;
863 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
864 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
866 /* Erase background */
867 if (gcdrf == CDRF_DODEFAULT ||
868 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
869 if (GetWindowTheme (infoPtr->hwndSelf)) {
870 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
872 else
873 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
874 if (gcdrf != CDRF_DODEFAULT)
875 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
878 /* draw channel */
879 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
880 nmcd.dwItemSpec = TBCD_CHANNEL;
881 nmcd.uItemState = CDIS_DEFAULT;
882 nmcd.rc = infoPtr->rcChannel;
883 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
884 } else icdrf = CDRF_DODEFAULT;
885 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
886 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
887 if (icdrf & CDRF_NOTIFYPOSTPAINT)
888 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
892 /* draw tics */
893 if (!(dwStyle & TBS_NOTICKS)) {
894 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
895 nmcd.dwItemSpec = TBCD_TICS;
896 nmcd.uItemState = CDIS_DEFAULT;
897 nmcd.rc = rcClient;
898 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
899 } else icdrf = CDRF_DODEFAULT;
900 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
901 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
902 if (icdrf & CDRF_NOTIFYPOSTPAINT)
903 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
907 /* draw thumb */
908 if (!(dwStyle & TBS_NOTHUMB)) {
909 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
910 nmcd.dwItemSpec = TBCD_THUMB;
911 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
912 nmcd.rc = infoPtr->rcThumb;
913 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
914 } else icdrf = CDRF_DODEFAULT;
915 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
916 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
917 if (icdrf & CDRF_NOTIFYPOSTPAINT)
918 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
922 /* draw focus rectangle */
923 if (infoPtr->bFocussed) {
924 DrawFocusRect(hdc, &rcClient);
927 /* finish up the painting */
928 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
929 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
931 cleanup:
932 /* cleanup, if we rendered offscreen */
933 if (hdc != hdcDst) {
934 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
935 SelectObject(hdc, hOldBmp);
936 DeleteObject(hOffScreenBmp);
937 DeleteObject(hdc);
942 static void
943 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
945 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
946 HWND hwndParent = GetParent (infoPtr->hwndSelf);
947 RECT rcSelf, rcBuddy;
948 INT x, y;
950 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
951 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
953 /* align buddy left or above */
954 if (infoPtr->hwndBuddyLA) {
955 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
956 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
958 if (dwStyle & TBS_VERT) {
959 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
960 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
961 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
963 else {
964 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
965 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
966 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
969 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
970 SWP_NOZORDER | SWP_NOSIZE);
974 /* align buddy right or below */
975 if (infoPtr->hwndBuddyRB) {
976 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
977 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
979 if (dwStyle & TBS_VERT) {
980 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
981 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
982 y = rcSelf.bottom;
984 else {
985 x = rcSelf.right;
986 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
987 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
989 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
990 SWP_NOZORDER | SWP_NOSIZE);
995 static LRESULT
996 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
998 infoPtr->lSelMin = 0;
999 infoPtr->lSelMax = 0;
1000 infoPtr->flags |= TB_SELECTIONCHANGED;
1002 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1004 return 0;
1008 static LRESULT
1009 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1011 if (infoPtr->tics) {
1012 Free (infoPtr->tics);
1013 infoPtr->tics = NULL;
1014 infoPtr->uNumTics = 0;
1017 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1019 return 0;
1023 static inline LRESULT
1024 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1026 if (lprc == NULL) return 0;
1028 lprc->left = infoPtr->rcChannel.left;
1029 lprc->right = infoPtr->rcChannel.right;
1030 lprc->bottom = infoPtr->rcChannel.bottom;
1031 lprc->top = infoPtr->rcChannel.top;
1033 return 0;
1037 static inline LONG
1038 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1040 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
1041 return 0;
1043 if(infoPtr->uNumTics == 0)
1044 return 2;
1045 else
1046 return infoPtr->uNumTics + 1;
1050 static int comp_tics (const void *ap, const void *bp)
1052 const DWORD a = *(const DWORD *)ap;
1053 const DWORD b = *(const DWORD *)bp;
1055 TRACE("(a=%d, b=%d)\n", a, b);
1056 if (a < b) return -1;
1057 if (a > b) return 1;
1058 return 0;
1062 static inline LONG
1063 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1065 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1066 return -1;
1068 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1069 return infoPtr->tics[iTic];
1073 static inline LONG
1074 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1076 LONG range, width, pos, tic;
1077 int offsetthumb;
1079 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1080 return -1;
1082 tic = TRACKBAR_GetTic (infoPtr, iTic);
1083 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1084 if (range <= 0) range = 1;
1085 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1086 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1087 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1089 return pos;
1093 static HWND
1094 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1096 HWND hwndTemp;
1098 if (fLocation) {
1099 /* buddy is left or above */
1100 hwndTemp = infoPtr->hwndBuddyLA;
1101 infoPtr->hwndBuddyLA = hwndBuddy;
1103 else {
1104 /* buddy is right or below */
1105 hwndTemp = infoPtr->hwndBuddyRB;
1106 infoPtr->hwndBuddyRB = hwndBuddy;
1109 TRACKBAR_AlignBuddies (infoPtr);
1111 return hwndTemp;
1115 static inline LONG
1116 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1118 LONG lTemp = infoPtr->lLineSize;
1120 infoPtr->lLineSize = lLineSize;
1122 return lTemp;
1126 static inline LONG
1127 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1129 LONG lTemp = infoPtr->lPageSize;
1131 infoPtr->lPageSize = lPageSize;
1133 return lTemp;
1137 static inline LRESULT
1138 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1140 LONG oldPos = infoPtr->lPos;
1141 infoPtr->lPos = lPosition;
1143 if (infoPtr->lPos < infoPtr->lRangeMin)
1144 infoPtr->lPos = infoPtr->lRangeMin;
1146 if (infoPtr->lPos > infoPtr->lRangeMax)
1147 infoPtr->lPos = infoPtr->lRangeMax;
1148 infoPtr->flags |= TB_THUMBPOSCHANGED;
1150 if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1152 return 0;
1156 static inline LRESULT
1157 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1159 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1160 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1162 if (infoPtr->lPos < infoPtr->lRangeMin) {
1163 infoPtr->lPos = infoPtr->lRangeMin;
1164 infoPtr->flags |= TB_THUMBPOSCHANGED;
1167 if (infoPtr->lPos > infoPtr->lRangeMax) {
1168 infoPtr->lPos = infoPtr->lRangeMax;
1169 infoPtr->flags |= TB_THUMBPOSCHANGED;
1172 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1173 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1175 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1177 return 0;
1181 static inline LRESULT
1182 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1184 infoPtr->lRangeMax = lMax;
1185 if (infoPtr->lPos > infoPtr->lRangeMax) {
1186 infoPtr->lPos = infoPtr->lRangeMax;
1187 infoPtr->flags |= TB_THUMBPOSCHANGED;
1190 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1191 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1193 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1195 return 0;
1199 static inline LRESULT
1200 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1202 infoPtr->lRangeMin = lMin;
1203 if (infoPtr->lPos < infoPtr->lRangeMin) {
1204 infoPtr->lPos = infoPtr->lRangeMin;
1205 infoPtr->flags |= TB_THUMBPOSCHANGED;
1208 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1209 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1211 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1213 return 0;
1217 static inline LRESULT
1218 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1220 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1221 infoPtr->lSelMin = 0;
1222 infoPtr->lSelMax = 0;
1223 return 0;
1226 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1227 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1228 infoPtr->flags |= TB_SELECTIONCHANGED;
1230 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1231 infoPtr->lSelMin = infoPtr->lRangeMin;
1232 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1233 infoPtr->lSelMax = infoPtr->lRangeMax;
1235 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1237 return 0;
1241 static inline LRESULT
1242 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1244 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1245 infoPtr->lSelMax = 0;
1246 return 0;
1249 infoPtr->lSelMax = lEnd;
1250 infoPtr->flags |= TB_SELECTIONCHANGED;
1252 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1253 infoPtr->lSelMax = infoPtr->lRangeMax;
1255 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1257 return 0;
1261 static inline LRESULT
1262 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1264 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1265 infoPtr->lSelMin = 0;
1266 return 0;
1269 infoPtr->lSelMin = lStart;
1270 infoPtr->flags |=TB_SELECTIONCHANGED;
1272 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1273 infoPtr->lSelMin = infoPtr->lRangeMin;
1275 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1277 return 0;
1281 static inline LRESULT
1282 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1284 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) {
1285 infoPtr->uThumbLen = iLength;
1286 infoPtr->flags |= TB_THUMBSIZECHANGED;
1287 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1290 return 0;
1294 static inline LRESULT
1295 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1297 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1298 return FALSE;
1300 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1301 return FALSE;
1303 TRACE("lPos=%d\n", lPos);
1305 infoPtr->uNumTics++;
1306 infoPtr->tics=ReAlloc( infoPtr->tics,
1307 (infoPtr->uNumTics)*sizeof (DWORD));
1308 if (!infoPtr->tics) {
1309 infoPtr->uNumTics = 0;
1310 notify(infoPtr, NM_OUTOFMEMORY);
1311 return FALSE;
1313 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1315 TRACKBAR_InvalidateAll(infoPtr);
1317 return TRUE;
1321 static inline LRESULT
1322 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1324 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1325 infoPtr->uTicFreq = wFreq;
1326 TRACKBAR_RecalculateTics (infoPtr);
1327 TRACKBAR_InvalidateAll(infoPtr);
1330 return 0;
1334 static inline INT
1335 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1337 INT fTemp = infoPtr->fLocation;
1339 infoPtr->fLocation = fLocation;
1341 return fTemp;
1345 static inline LRESULT
1346 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1348 infoPtr->hwndToolTip = hwndTT;
1350 return 0;
1354 static inline BOOL
1355 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1357 BOOL bTemp = infoPtr->bUnicode;
1359 infoPtr->bUnicode = fUnicode;
1361 return bTemp;
1365 static LRESULT
1366 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1368 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1369 RECT rect;
1370 int clientWidth, clientMetric;
1372 /* initial thumb length */
1373 clientMetric = (dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1374 GetClientRect(infoPtr->hwndSelf,&rect);
1375 if (dwStyle & TBS_VERT) {
1376 clientWidth = rect.right - rect.left;
1377 } else {
1378 clientWidth = rect.bottom - rect.top;
1380 if (clientWidth >= clientMetric)
1381 infoPtr->uThumbLen = clientMetric;
1382 else
1383 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1385 TRACKBAR_CalcChannel (infoPtr);
1386 TRACKBAR_UpdateThumb (infoPtr);
1387 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1389 return 0;
1393 static LRESULT
1394 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1396 TRACKBAR_INFO *infoPtr;
1397 DWORD dwStyle;
1399 infoPtr = (TRACKBAR_INFO *)Alloc (sizeof(TRACKBAR_INFO));
1400 if (!infoPtr) return -1;
1401 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1403 /* set default values */
1404 infoPtr->hwndSelf = hwnd;
1405 infoPtr->lRangeMin = 0;
1406 infoPtr->lRangeMax = 100;
1407 infoPtr->lLineSize = 1;
1408 infoPtr->lPageSize = 20;
1409 infoPtr->lSelMin = 0;
1410 infoPtr->lSelMax = 0;
1411 infoPtr->lPos = 0;
1412 infoPtr->fLocation = -1;
1413 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1414 infoPtr->uTicFreq = 1;
1415 infoPtr->tics = NULL;
1416 infoPtr->hwndNotify= lpcs->hwndParent;
1418 TRACKBAR_InitializeThumb (infoPtr);
1420 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1422 /* Create tooltip control */
1423 if (dwStyle & TBS_TOOLTIPS) {
1425 infoPtr->hwndToolTip =
1426 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1427 CW_USEDEFAULT, CW_USEDEFAULT,
1428 CW_USEDEFAULT, CW_USEDEFAULT,
1429 hwnd, 0, 0, 0);
1431 if (infoPtr->hwndToolTip) {
1432 TTTOOLINFOW ti;
1433 ZeroMemory (&ti, sizeof(ti));
1434 ti.cbSize = sizeof(ti);
1435 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1436 ti.hwnd = hwnd;
1438 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1442 OpenThemeData (hwnd, themeClass);
1444 return 0;
1448 static LRESULT
1449 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1451 /* delete tooltip control */
1452 if (infoPtr->hwndToolTip)
1453 DestroyWindow (infoPtr->hwndToolTip);
1455 Free (infoPtr);
1456 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1457 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1458 return 0;
1462 static LRESULT
1463 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
1465 TRACE("\n");
1466 infoPtr->bFocussed = FALSE;
1467 TRACKBAR_InvalidateAll(infoPtr);
1469 return 0;
1472 static LRESULT
1473 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1475 POINT clickPoint;
1477 clickPoint.x = x;
1478 clickPoint.y = y;
1480 SetFocus(infoPtr->hwndSelf);
1482 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1483 infoPtr->flags |= TB_DRAG_MODE;
1484 SetCapture (infoPtr->hwndSelf);
1485 TRACKBAR_UpdateToolTip (infoPtr);
1486 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1487 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1488 } else {
1489 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1490 if (dir == 0) return 0;
1491 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1492 TRACKBAR_AutoPage (infoPtr, clickPoint);
1493 SetCapture (infoPtr->hwndSelf);
1494 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1497 return 0;
1501 static LRESULT
1502 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1504 if (infoPtr->flags & TB_DRAG_MODE) {
1505 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1506 notify_with_scroll (infoPtr, TB_ENDTRACK);
1507 infoPtr->flags &= ~TB_DRAG_MODE;
1508 ReleaseCapture ();
1509 notify(infoPtr, NM_RELEASEDCAPTURE);
1510 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1511 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1513 if (infoPtr->flags & TB_AUTO_PAGE) {
1514 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1515 infoPtr->flags &= ~TB_AUTO_PAGE;
1516 notify_with_scroll (infoPtr, TB_ENDTRACK);
1517 ReleaseCapture ();
1518 notify(infoPtr, NM_RELEASEDCAPTURE);
1521 return 0;
1525 static LRESULT
1526 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1528 notify_with_scroll (infoPtr, TB_ENDTRACK);
1529 return 0;
1533 static LRESULT
1534 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1536 if (hdc) {
1537 TRACKBAR_Refresh(infoPtr, hdc);
1538 } else {
1539 PAINTSTRUCT ps;
1540 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1541 TRACKBAR_Refresh (infoPtr, hdc);
1542 EndPaint (infoPtr->hwndSelf, &ps);
1545 return 0;
1549 static LRESULT
1550 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
1552 TRACE("\n");
1553 infoPtr->bFocussed = TRUE;
1554 TRACKBAR_InvalidateAll(infoPtr);
1556 return 0;
1560 static LRESULT
1561 TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
1563 TRACKBAR_InitializeThumb (infoPtr);
1564 TRACKBAR_AlignBuddies (infoPtr);
1566 return 0;
1570 static LRESULT
1571 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, const TIMERPROC *tmrpc)
1573 if (infoPtr->flags & TB_AUTO_PAGE) {
1574 POINT pt;
1575 if (GetCursorPos(&pt))
1576 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1577 TRACKBAR_AutoPage(infoPtr, pt);
1579 return 0;
1583 /* update theme after a WM_THEMECHANGED message */
1584 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1586 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1587 CloseThemeData (theme);
1588 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
1589 return 0;
1593 static LRESULT
1594 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1596 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1597 INT clickPlace = (dwStyle & TBS_VERT) ? y : x;
1598 LONG dragPos, oldPos = infoPtr->lPos;
1600 TRACE("(x=%d. y=%d)\n", x, y);
1602 if (infoPtr->flags & TB_AUTO_PAGE) {
1603 POINT pt;
1604 pt.x = x;
1605 pt.y = y;
1606 TRACKBAR_AutoPage (infoPtr, pt);
1607 return TRUE;
1610 if (!(infoPtr->flags & TB_DRAG_MODE))
1612 if (GetWindowTheme (infoPtr->hwndSelf))
1614 DWORD oldFlags = infoPtr->flags;
1615 POINT pt;
1616 pt.x = x;
1617 pt.y = y;
1618 if (PtInRect (&infoPtr->rcThumb, pt))
1620 TRACKMOUSEEVENT tme;
1621 tme.cbSize = sizeof( tme );
1622 tme.dwFlags = TME_LEAVE;
1623 tme.hwndTrack = infoPtr->hwndSelf;
1624 TrackMouseEvent( &tme );
1625 infoPtr->flags |= TB_THUMB_HOT;
1627 else
1629 TRACKMOUSEEVENT tme;
1630 tme.cbSize = sizeof( tme );
1631 tme.dwFlags = TME_CANCEL;
1632 tme.hwndTrack = infoPtr->hwndSelf;
1633 TrackMouseEvent( &tme );
1634 infoPtr->flags &= ~TB_THUMB_HOT;
1636 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1638 return TRUE;
1641 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1642 dwStyle & TBS_VERT);
1643 if (dragPos == oldPos) return TRUE;
1645 infoPtr->lPos = dragPos;
1647 infoPtr->flags |= TB_THUMBPOSCHANGED;
1648 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1651 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1652 UpdateWindow (infoPtr->hwndSelf);
1654 return TRUE;
1657 static BOOL
1658 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1660 DWORD style = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1661 BOOL downIsLeft = style & TBS_DOWNISLEFT;
1662 BOOL vert = style & TBS_VERT;
1663 LONG pos = infoPtr->lPos;
1665 TRACE("%x\n", nVirtKey);
1667 switch (nVirtKey) {
1668 case VK_UP:
1669 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1670 else TRACKBAR_LineUp(infoPtr);
1671 break;
1672 case VK_LEFT:
1673 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1674 else TRACKBAR_LineUp(infoPtr);
1675 break;
1676 case VK_DOWN:
1677 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1678 else TRACKBAR_LineDown(infoPtr);
1679 break;
1680 case VK_RIGHT:
1681 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1682 else TRACKBAR_LineDown(infoPtr);
1683 break;
1684 case VK_NEXT:
1685 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1686 else TRACKBAR_PageDown(infoPtr);
1687 break;
1688 case VK_PRIOR:
1689 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1690 else TRACKBAR_PageUp(infoPtr);
1691 break;
1692 case VK_HOME:
1693 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1694 infoPtr->lPos = infoPtr->lRangeMin;
1695 notify_with_scroll (infoPtr, TB_TOP);
1696 break;
1697 case VK_END:
1698 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1699 infoPtr->lPos = infoPtr->lRangeMax;
1700 notify_with_scroll (infoPtr, TB_BOTTOM);
1701 break;
1704 if (pos != infoPtr->lPos) {
1705 infoPtr->flags |=TB_THUMBPOSCHANGED;
1706 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1709 return TRUE;
1713 static inline BOOL
1714 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1716 switch (nVirtKey) {
1717 case VK_LEFT:
1718 case VK_UP:
1719 case VK_RIGHT:
1720 case VK_DOWN:
1721 case VK_NEXT:
1722 case VK_PRIOR:
1723 case VK_HOME:
1724 case VK_END:
1725 notify_with_scroll (infoPtr, TB_ENDTRACK);
1727 return TRUE;
1731 static LRESULT WINAPI
1732 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1734 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1736 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1738 if (!infoPtr && (uMsg != WM_CREATE))
1739 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1741 switch (uMsg)
1743 case TBM_CLEARSEL:
1744 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1746 case TBM_CLEARTICS:
1747 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1749 case TBM_GETBUDDY:
1750 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1752 case TBM_GETCHANNELRECT:
1753 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1755 case TBM_GETLINESIZE:
1756 return infoPtr->lLineSize;
1758 case TBM_GETNUMTICS:
1759 return TRACKBAR_GetNumTics (infoPtr);
1761 case TBM_GETPAGESIZE:
1762 return infoPtr->lPageSize;
1764 case TBM_GETPOS:
1765 return infoPtr->lPos;
1767 case TBM_GETPTICS:
1768 return (LRESULT)infoPtr->tics;
1770 case TBM_GETRANGEMAX:
1771 return infoPtr->lRangeMax;
1773 case TBM_GETRANGEMIN:
1774 return infoPtr->lRangeMin;
1776 case TBM_GETSELEND:
1777 return infoPtr->lSelMax;
1779 case TBM_GETSELSTART:
1780 return infoPtr->lSelMin;
1782 case TBM_GETTHUMBLENGTH:
1783 return infoPtr->uThumbLen;
1785 case TBM_GETTHUMBRECT:
1786 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1788 case TBM_GETTIC:
1789 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1791 case TBM_GETTICPOS:
1792 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1794 case TBM_GETTOOLTIPS:
1795 return (LRESULT)infoPtr->hwndToolTip;
1797 case TBM_GETUNICODEFORMAT:
1798 return infoPtr->bUnicode;
1800 case TBM_SETBUDDY:
1801 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1803 case TBM_SETLINESIZE:
1804 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1806 case TBM_SETPAGESIZE:
1807 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1809 case TBM_SETPOS:
1810 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1812 case TBM_SETRANGE:
1813 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1815 case TBM_SETRANGEMAX:
1816 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1818 case TBM_SETRANGEMIN:
1819 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1821 case TBM_SETSEL:
1822 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1824 case TBM_SETSELEND:
1825 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1827 case TBM_SETSELSTART:
1828 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1830 case TBM_SETTHUMBLENGTH:
1831 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1833 case TBM_SETTIC:
1834 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1836 case TBM_SETTICFREQ:
1837 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1839 case TBM_SETTIPSIDE:
1840 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1842 case TBM_SETTOOLTIPS:
1843 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1845 case TBM_SETUNICODEFORMAT:
1846 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1849 case WM_CAPTURECHANGED:
1850 return TRACKBAR_CaptureChanged (infoPtr);
1852 case WM_CREATE:
1853 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1855 case WM_DESTROY:
1856 return TRACKBAR_Destroy (infoPtr);
1858 /* case WM_ENABLE: */
1860 case WM_ERASEBKGND:
1861 return 0;
1863 case WM_GETDLGCODE:
1864 return DLGC_WANTARROWS;
1866 case WM_KEYDOWN:
1867 return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
1869 case WM_KEYUP:
1870 return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
1872 case WM_KILLFOCUS:
1873 return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
1875 case WM_LBUTTONDOWN:
1876 return TRACKBAR_LButtonDown (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1878 case WM_LBUTTONUP:
1879 return TRACKBAR_LButtonUp (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1881 case WM_MOUSELEAVE:
1882 infoPtr->flags &= ~TB_THUMB_HOT;
1883 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1884 return 0;
1886 case WM_MOUSEMOVE:
1887 return TRACKBAR_MouseMove (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1889 case WM_PRINTCLIENT:
1890 case WM_PAINT:
1891 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1893 case WM_SETFOCUS:
1894 return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
1896 case WM_SIZE:
1897 return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
1899 case WM_THEMECHANGED:
1900 return theme_changed (infoPtr);
1902 case WM_TIMER:
1903 return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
1905 case WM_WININICHANGE:
1906 return TRACKBAR_InitializeThumb (infoPtr);
1908 default:
1909 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1910 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
1911 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1916 void TRACKBAR_Register (void)
1918 WNDCLASSW wndClass;
1920 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1921 wndClass.style = CS_GLOBALCLASS;
1922 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1923 wndClass.cbClsExtra = 0;
1924 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1925 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1926 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1927 wndClass.lpszClassName = TRACKBAR_CLASSW;
1929 RegisterClassW (&wndClass);
1933 void TRACKBAR_Unregister (void)
1935 UnregisterClassW (TRACKBAR_CLASSW, NULL);