gdi: Fix test for GetGlyphIndicesW on non Unicode systems.
[wine/hacks.git] / dlls / comctl32 / trackbar.c
blob615df572a508d6dd6430180d74e2da5d1b67d1c4
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(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(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,
123 (WPARAM)pnmh->idFrom, (LPARAM)pnmh);
125 TRACE(" <= %ld\n", result);
127 return result;
130 static inline int notify(TRACKBAR_INFO *infoPtr, INT code)
132 NMHDR nmh;
133 return notify_hdr(infoPtr, code, &nmh);
136 static BOOL
137 notify_with_scroll (TRACKBAR_INFO *infoPtr, UINT code)
139 BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT;
141 TRACE("%x\n", code);
143 return (BOOL) SendMessageW (infoPtr->hwndNotify,
144 bVert ? WM_VSCROLL : WM_HSCROLL,
145 (WPARAM)code, (LPARAM)infoPtr->hwndSelf);
148 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
150 int i, tic, nrTics;
152 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin)
153 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
154 else {
155 nrTics = 0;
156 Free (infoPtr->tics);
157 infoPtr->tics = NULL;
158 infoPtr->uNumTics = 0;
159 return;
162 if (nrTics != infoPtr->uNumTics) {
163 infoPtr->tics=ReAlloc (infoPtr->tics,
164 (nrTics+1)*sizeof (DWORD));
165 if (!infoPtr->tics) {
166 infoPtr->uNumTics = 0;
167 notify(infoPtr, NM_OUTOFMEMORY);
168 return;
170 infoPtr->uNumTics = nrTics;
173 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
174 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
175 infoPtr->tics[i] = tic;
178 /* converts from physical (mouse) position to logical position
179 (in range of trackbar) */
181 static inline LONG
182 TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO *infoPtr, int place,
183 int vertical)
185 double range, width, pos, offsetthumb;
187 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
188 if (vertical) {
189 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
190 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
191 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
192 } else {
193 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
194 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
195 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
197 pos += infoPtr->lRangeMin;
198 if (pos > infoPtr->lRangeMax)
199 pos = infoPtr->lRangeMax;
200 else if (pos < infoPtr->lRangeMin)
201 pos = infoPtr->lRangeMin;
203 TRACE("%.2f\n", pos);
204 return (LONG)(pos + 0.5);
208 /* return: 0> prev, 0 none, >0 next */
209 static LONG
210 TRACKBAR_GetAutoPageDirection (TRACKBAR_INFO *infoPtr, POINT clickPoint)
212 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
213 RECT pageRect;
215 if (dwStyle & TBS_VERT) {
216 pageRect.top = infoPtr->rcChannel.top;
217 pageRect.bottom = infoPtr->rcChannel.bottom;
218 pageRect.left = infoPtr->rcThumb.left;
219 pageRect.right = infoPtr->rcThumb.right;
220 } else {
221 pageRect.top = infoPtr->rcThumb.top;
222 pageRect.bottom = infoPtr->rcThumb.bottom;
223 pageRect.left = infoPtr->rcChannel.left;
224 pageRect.right = infoPtr->rcChannel.right;
228 if (PtInRect(&pageRect, clickPoint))
230 int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
232 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace,
233 dwStyle & TBS_VERT);
234 return clickPos - infoPtr->lPos;
237 return 0;
240 inline static void
241 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
243 if (infoPtr->lPos == infoPtr->lRangeMax) return;
245 infoPtr->lPos += infoPtr->lPageSize;
246 if (infoPtr->lPos > infoPtr->lRangeMax)
247 infoPtr->lPos = infoPtr->lRangeMax;
248 notify_with_scroll (infoPtr, TB_PAGEDOWN);
252 inline static void
253 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
255 if (infoPtr->lPos == infoPtr->lRangeMin) return;
257 infoPtr->lPos -= infoPtr->lPageSize;
258 if (infoPtr->lPos < infoPtr->lRangeMin)
259 infoPtr->lPos = infoPtr->lRangeMin;
260 notify_with_scroll (infoPtr, TB_PAGEUP);
263 inline static void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
265 if (infoPtr->lPos == infoPtr->lRangeMin) return;
266 infoPtr->lPos -= infoPtr->lLineSize;
267 if (infoPtr->lPos < infoPtr->lRangeMin)
268 infoPtr->lPos = infoPtr->lRangeMin;
269 notify_with_scroll (infoPtr, TB_LINEUP);
272 inline static void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
274 if (infoPtr->lPos == infoPtr->lRangeMax) return;
275 infoPtr->lPos += infoPtr->lLineSize;
276 if (infoPtr->lPos > infoPtr->lRangeMax)
277 infoPtr->lPos = infoPtr->lRangeMax;
278 notify_with_scroll (infoPtr, TB_LINEDOWN);
281 static void
282 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
284 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
285 INT cyChannel, offsetthumb, offsetedge;
286 RECT lpRect, *channel = & infoPtr->rcChannel;
288 GetClientRect (infoPtr->hwndSelf, &lpRect);
290 offsetthumb = infoPtr->uThumbLen / 4;
291 offsetedge = offsetthumb + 3;
292 cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
293 if (dwStyle & TBS_VERT) {
294 channel->top = lpRect.top + offsetedge;
295 channel->bottom = lpRect.bottom - offsetedge;
296 if (dwStyle & TBS_ENABLESELRANGE)
297 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
298 else
299 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
300 if (dwStyle & TBS_BOTH) {
301 if (dwStyle & TBS_NOTICKS)
302 channel->left += 1;
303 else
304 channel->left += 9;
306 else if (dwStyle & TBS_TOP) {
307 if (dwStyle & TBS_NOTICKS)
308 channel->left += 2;
309 else
310 channel->left += 10;
312 channel->right = channel->left + cyChannel;
313 } else {
314 channel->left = lpRect.left + offsetedge;
315 channel->right = lpRect.right - offsetedge;
316 if (dwStyle & TBS_ENABLESELRANGE)
317 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
318 else
319 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
320 if (dwStyle & TBS_BOTH) {
321 if (dwStyle & TBS_NOTICKS)
322 channel->top += 1;
323 else
324 channel->top += 9;
326 else if (dwStyle & TBS_TOP) {
327 if (dwStyle & TBS_NOTICKS)
328 channel->top += 2;
329 else
330 channel->top += 10;
332 channel->bottom = channel->top + cyChannel;
336 static void
337 TRACKBAR_CalcThumb (TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
339 int range, width, height, thumbwidth;
340 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
341 RECT lpRect;
343 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
344 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
346 if (!range) range = 1;
348 GetClientRect(infoPtr->hwndSelf, &lpRect);
349 if (dwStyle & TBS_VERT)
351 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
353 if ((dwStyle & (TBS_BOTH | TBS_LEFT)) && !(dwStyle & TBS_NOTICKS))
354 thumb->left = 10;
355 else
356 thumb->left = 2;
357 thumb->right = thumb->left + infoPtr->uThumbLen;
358 thumb->top = infoPtr->rcChannel.top +
359 (height*(lPos - infoPtr->lRangeMin))/range;
360 thumb->bottom = thumb->top + thumbwidth;
362 else
364 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
366 thumb->left = infoPtr->rcChannel.left +
367 (width*(lPos - infoPtr->lRangeMin))/range;
368 thumb->right = thumb->left + thumbwidth;
369 if ((dwStyle & (TBS_BOTH | TBS_TOP)) && !(dwStyle & TBS_NOTICKS))
370 thumb->top = 10;
371 else
372 thumb->top = 2;
373 thumb->bottom = thumb->top + infoPtr->uThumbLen;
377 inline static void
378 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
380 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
383 static inline void
384 TRACKBAR_InvalidateAll(TRACKBAR_INFO * infoPtr)
386 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
389 static void
390 TRACKBAR_InvalidateThumb (TRACKBAR_INFO *infoPtr, LONG thumbPos)
392 RECT rcThumb;
394 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
395 InflateRect(&rcThumb, 1, 1);
396 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
399 static inline void
400 TRACKBAR_InvalidateThumbMove (TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
402 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
403 if (newPos != oldPos)
404 TRACKBAR_InvalidateThumb (infoPtr, newPos);
407 inline static BOOL
408 TRACKBAR_HasSelection (TRACKBAR_INFO *infoPtr)
410 return infoPtr->lSelMin != infoPtr->lSelMax;
413 static void
414 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
416 RECT *selection = &infoPtr->rcSelection;
417 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
418 int offsetthumb, height, width;
420 if (range <= 0) {
421 SetRectEmpty (selection);
422 } else {
423 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) {
424 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
425 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
426 selection->top = infoPtr->rcChannel.top + offsetthumb +
427 (height*infoPtr->lSelMin)/range;
428 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
429 (height*infoPtr->lSelMax)/range;
430 selection->left = infoPtr->rcChannel.left + 3;
431 selection->right = infoPtr->rcChannel.right - 3;
432 } else {
433 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
434 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
435 selection->left = infoPtr->rcChannel.left + offsetthumb +
436 (width*infoPtr->lSelMin)/range;
437 selection->right = infoPtr->rcChannel.left + offsetthumb +
438 (width*infoPtr->lSelMax)/range;
439 selection->top = infoPtr->rcChannel.top + 3;
440 selection->bottom = infoPtr->rcChannel.bottom - 3;
444 TRACE("selection[left=%ld, top=%ld, right=%ld, bottom=%ld]\n",
445 selection->left, selection->top, selection->right, selection->bottom);
448 static BOOL
449 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
451 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
452 LONG prevPos = infoPtr->lPos;
454 TRACE("x=%ld, y=%ld, dir=%ld\n", clickPoint.x, clickPoint.y, dir);
456 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
457 TRACKBAR_PageDown(infoPtr);
458 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
459 TRACKBAR_PageUp(infoPtr);
460 else return FALSE;
462 infoPtr->flags |= TB_THUMBPOSCHANGED;
463 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
465 return TRUE;
468 /* Trackbar drawing code. I like my spaghetti done milanese. */
470 static void
471 TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
473 RECT rcChannel = infoPtr->rcChannel;
474 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
476 if (theme)
478 DrawThemeBackground (theme, hdc,
479 (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) ?
480 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
482 else
484 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
485 if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
486 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
487 if (TRACKBAR_HasSelection(infoPtr))
488 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
493 static void
494 TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
496 int x, y, ox, oy, range, side, indent = 0, len = 3;
497 int offsetthumb;
498 RECT rcTics;
500 if (flags & TBS_VERT) {
501 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
502 rcTics.left = infoPtr->rcThumb.left - 2;
503 rcTics.right = infoPtr->rcThumb.right + 2;
504 rcTics.top = infoPtr->rcChannel.top + offsetthumb + 1;
505 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb;
506 } else {
507 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
508 rcTics.left = infoPtr->rcChannel.left + offsetthumb + 1;
509 rcTics.right = infoPtr->rcChannel.right - offsetthumb;
510 rcTics.top = infoPtr->rcThumb.top - 2;
511 rcTics.bottom = infoPtr->rcThumb.bottom + 2;
514 if (flags & (TBS_TOP | TBS_LEFT)) {
515 x = rcTics.left;
516 y = rcTics.top;
517 side = -1;
518 } else {
519 x = rcTics.right;
520 y = rcTics.bottom;
521 side = 1;
524 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
525 if (range <= 0)
526 range = 1; /* to avoid division by zero */
528 if (flags & TIC_SELECTIONMARK) {
529 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
530 } else if (flags & TIC_EDGE) {
531 len++;
534 if (flags & TBS_VERT) {
535 int height = rcTics.bottom - rcTics.top;
536 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
537 } else {
538 int width = rcTics.right - rcTics.left;
539 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
542 ox = x;
543 oy = y;
544 MoveToEx(hdc, x, y, 0);
545 if (flags & TBS_VERT) x += len * side;
546 else y += len * side;
547 LineTo(hdc, x, y);
549 if (flags & TIC_SELECTIONMARK) {
550 if (flags & TBS_VERT) {
551 x -= side;
552 } else {
553 y -= side;
555 MoveToEx(hdc, x, y, 0);
556 if (flags & TBS_VERT) {
557 y += 2 * indent;
558 } else {
559 x += 2 * indent;
562 LineTo(hdc, x, y);
563 LineTo(hdc, ox, oy);
568 static inline void
569 TRACKBAR_DrawTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
571 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
572 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
574 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
575 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
578 static void
579 TRACKBAR_DrawTics (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
581 unsigned int i;
582 int ticFlags = dwStyle & 0x0f;
583 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
584 HPEN hOldPen, hTicPen;
585 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
587 if (theme)
589 int part = (dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
590 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
592 /* create the pen to draw the tics with */
593 hTicPen = CreatePenIndirect(&ticPen);
594 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
596 /* actually draw the tics */
597 for (i=0; i<infoPtr->uNumTics; i++)
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
600 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
601 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
603 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
604 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
605 ticFlags | TIC_SELECTIONMARKMIN);
606 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
607 ticFlags | TIC_SELECTIONMARKMAX);
610 /* clean up the pen, if we created one */
611 if (hTicPen) {
612 SelectObject(hdc, hOldPen);
613 DeleteObject(hTicPen);
617 static void
618 TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
620 HBRUSH oldbr;
621 HPEN oldpen;
622 RECT thumb = infoPtr->rcThumb;
623 int BlackUntil = 3;
624 int PointCount = 6;
625 POINT points[6];
626 int fillClr;
627 int PointDepth;
628 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
630 if (theme)
632 int partId;
633 int stateId;
634 if (dwStyle & TBS_BOTH)
635 partId = (dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
636 else if (dwStyle & TBS_LEFT)
637 partId = (dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
638 else
639 partId = (dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
641 if (dwStyle & WS_DISABLED)
642 stateId = TUS_DISABLED;
643 else if (infoPtr->flags & TB_DRAG_MODE)
644 stateId = TUS_PRESSED;
645 else if (infoPtr->flags & TB_THUMB_HOT)
646 stateId = TUS_HOT;
647 else
648 stateId = TUS_NORMAL;
650 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
652 return;
655 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
656 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
657 SetPolyFillMode (hdc, WINDING);
659 if (dwStyle & TBS_BOTH)
661 points[0].x=thumb.right;
662 points[0].y=thumb.top;
663 points[1].x=thumb.right;
664 points[1].y=thumb.bottom;
665 points[2].x=thumb.left;
666 points[2].y=thumb.bottom;
667 points[3].x=thumb.left;
668 points[3].y=thumb.top;
669 points[4].x=points[0].x;
670 points[4].y=points[0].y;
671 PointCount = 5;
672 BlackUntil = 3;
674 else
676 if (dwStyle & TBS_VERT)
678 PointDepth = (thumb.bottom - thumb.top) / 2;
679 if (dwStyle & TBS_LEFT)
681 points[0].x=thumb.right;
682 points[0].y=thumb.top;
683 points[1].x=thumb.right;
684 points[1].y=thumb.bottom;
685 points[2].x=thumb.left + PointDepth;
686 points[2].y=thumb.bottom;
687 points[3].x=thumb.left;
688 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
689 points[4].x=thumb.left + PointDepth;
690 points[4].y=thumb.top;
691 points[5].x=points[0].x;
692 points[5].y=points[0].y;
693 BlackUntil = 4;
695 else
697 points[0].x=thumb.right;
698 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
699 points[1].x=thumb.right - PointDepth;
700 points[1].y=thumb.bottom;
701 points[2].x=thumb.left;
702 points[2].y=thumb.bottom;
703 points[3].x=thumb.left;
704 points[3].y=thumb.top;
705 points[4].x=thumb.right - PointDepth;
706 points[4].y=thumb.top;
707 points[5].x=points[0].x;
708 points[5].y=points[0].y;
711 else
713 PointDepth = (thumb.right - thumb.left) / 2;
714 if (dwStyle & TBS_TOP)
716 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
717 points[0].y=thumb.top;
718 points[1].x=thumb.right;
719 points[1].y=thumb.top + PointDepth;
720 points[2].x=thumb.right;
721 points[2].y=thumb.bottom;
722 points[3].x=thumb.left;
723 points[3].y=thumb.bottom;
724 points[4].x=thumb.left;
725 points[4].y=thumb.top + PointDepth;
726 points[5].x=points[0].x;
727 points[5].y=points[0].y;
728 BlackUntil = 4;
730 else
732 points[0].x=thumb.right;
733 points[0].y=thumb.top;
734 points[1].x=thumb.right;
735 points[1].y=thumb.bottom - PointDepth;
736 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
737 points[2].y=thumb.bottom;
738 points[3].x=thumb.left;
739 points[3].y=thumb.bottom - PointDepth;
740 points[4].x=thumb.left;
741 points[4].y=thumb.top;
742 points[5].x=points[0].x;
743 points[5].y=points[0].y;
749 /* Draw the thumb now */
750 Polygon (hdc, points, PointCount);
751 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
752 Polyline(hdc,points, BlackUntil);
753 SelectObject(hdc, GetStockObject(WHITE_PEN));
754 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
755 SelectObject(hdc, oldpen);
756 SelectObject(hdc, oldbr);
760 inline static void
761 TRACKBAR_ActivateToolTip (TRACKBAR_INFO *infoPtr, BOOL fShow)
763 TTTOOLINFOW ti;
765 if (!infoPtr->hwndToolTip) return;
767 ZeroMemory(&ti, sizeof(ti));
768 ti.cbSize = sizeof(ti);
769 ti.hwnd = infoPtr->hwndSelf;
771 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
775 static void
776 TRACKBAR_UpdateToolTip (TRACKBAR_INFO *infoPtr)
778 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
779 WCHAR buf[80];
780 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
781 TTTOOLINFOW ti;
782 POINT pt;
783 RECT rcClient;
784 LRESULT size;
786 if (!infoPtr->hwndToolTip) return;
788 ZeroMemory(&ti, sizeof(ti));
789 ti.cbSize = sizeof(ti);
790 ti.hwnd = infoPtr->hwndSelf;
791 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
793 wsprintfW (buf, fmt, infoPtr->lPos);
794 ti.lpszText = buf;
795 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
797 GetClientRect (infoPtr->hwndSelf, &rcClient);
798 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
799 if (dwStyle & TBS_VERT) {
800 if (infoPtr->fLocation == TBTS_LEFT)
801 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
802 else
803 pt.x = rcClient.right + TOOLTIP_OFFSET;
804 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
805 } else {
806 if (infoPtr->fLocation == TBTS_TOP)
807 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
808 else
809 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
810 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
812 ClientToScreen(infoPtr->hwndSelf, &pt);
814 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
815 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
819 static void
820 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
822 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
823 RECT rcClient;
824 HDC hdc;
825 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
826 NMCUSTOMDRAW nmcd;
827 int gcdrf, icdrf;
829 if (infoPtr->flags & TB_THUMBCHANGED) {
830 TRACKBAR_UpdateThumb (infoPtr);
831 if (infoPtr->flags & TB_THUMBSIZECHANGED)
832 TRACKBAR_CalcChannel (infoPtr);
834 if (infoPtr->flags & TB_SELECTIONCHANGED)
835 TRACKBAR_CalcSelection (infoPtr);
837 if (infoPtr->flags & TB_DRAG_MODE)
838 TRACKBAR_UpdateToolTip (infoPtr);
840 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
842 GetClientRect (infoPtr->hwndSelf, &rcClient);
844 /* try to render offscreen, if we fail, carrry onscreen */
845 hdc = CreateCompatibleDC(hdcDst);
846 if (hdc) {
847 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
848 if (hOffScreenBmp) {
849 hOldBmp = SelectObject(hdc, hOffScreenBmp);
850 } else {
851 DeleteObject(hdc);
852 hdc = hdcDst;
854 } else {
855 hdc = hdcDst;
858 ZeroMemory(&nmcd, sizeof(nmcd));
859 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
860 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
861 nmcd.hdr.code = NM_CUSTOMDRAW;
862 nmcd.hdc = hdc;
864 /* start the paint cycle */
865 nmcd.rc = rcClient;
866 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
867 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
869 /* Erase backbround */
870 if (gcdrf == CDRF_DODEFAULT ||
871 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
872 if (GetWindowTheme (infoPtr->hwndSelf))
873 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, &rcClient);
874 else
875 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
876 if (gcdrf != CDRF_DODEFAULT)
877 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
880 /* draw channel */
881 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
882 nmcd.dwItemSpec = TBCD_CHANNEL;
883 nmcd.uItemState = CDIS_DEFAULT;
884 nmcd.rc = infoPtr->rcChannel;
885 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
886 } else icdrf = CDRF_DODEFAULT;
887 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
888 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
889 if (icdrf & CDRF_NOTIFYPOSTPAINT)
890 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
894 /* draw tics */
895 if (!(dwStyle & TBS_NOTICKS)) {
896 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
897 nmcd.dwItemSpec = TBCD_TICS;
898 nmcd.uItemState = CDIS_DEFAULT;
899 nmcd.rc = rcClient;
900 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
901 } else icdrf = CDRF_DODEFAULT;
902 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
903 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
904 if (icdrf & CDRF_NOTIFYPOSTPAINT)
905 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
909 /* draw thumb */
910 if (!(dwStyle & TBS_NOTHUMB)) {
911 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
912 nmcd.dwItemSpec = TBCD_THUMB;
913 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
914 nmcd.rc = infoPtr->rcThumb;
915 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
916 } else icdrf = CDRF_DODEFAULT;
917 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
918 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
919 if (icdrf & CDRF_NOTIFYPOSTPAINT)
920 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
924 /* draw focus rectangle */
925 if (infoPtr->bFocussed) {
926 DrawFocusRect(hdc, &rcClient);
929 /* finish up the painting */
930 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
931 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
933 cleanup:
934 /* cleanup, if we rendered offscreen */
935 if (hdc != hdcDst) {
936 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
937 SelectObject(hdc, hOldBmp);
938 DeleteObject(hOffScreenBmp);
939 DeleteObject(hdc);
944 static void
945 TRACKBAR_AlignBuddies (TRACKBAR_INFO *infoPtr)
947 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
948 HWND hwndParent = GetParent (infoPtr->hwndSelf);
949 RECT rcSelf, rcBuddy;
950 INT x, y;
952 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
953 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
955 /* align buddy left or above */
956 if (infoPtr->hwndBuddyLA) {
957 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
958 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
960 if (dwStyle & TBS_VERT) {
961 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
962 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
963 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
965 else {
966 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
967 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
968 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
971 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
972 SWP_NOZORDER | SWP_NOSIZE);
976 /* align buddy right or below */
977 if (infoPtr->hwndBuddyRB) {
978 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
979 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
981 if (dwStyle & TBS_VERT) {
982 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
983 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
984 y = rcSelf.bottom;
986 else {
987 x = rcSelf.right;
988 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
989 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
991 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
992 SWP_NOZORDER | SWP_NOSIZE);
997 static LRESULT
998 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1000 infoPtr->lSelMin = 0;
1001 infoPtr->lSelMax = 0;
1002 infoPtr->flags |= TB_SELECTIONCHANGED;
1004 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1006 return 0;
1010 static LRESULT
1011 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1013 if (infoPtr->tics) {
1014 Free (infoPtr->tics);
1015 infoPtr->tics = NULL;
1016 infoPtr->uNumTics = 0;
1019 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1021 return 0;
1025 inline static LRESULT
1026 TRACKBAR_GetChannelRect (TRACKBAR_INFO *infoPtr, LPRECT lprc)
1028 if (lprc == NULL) return 0;
1030 lprc->left = infoPtr->rcChannel.left;
1031 lprc->right = infoPtr->rcChannel.right;
1032 lprc->bottom = infoPtr->rcChannel.bottom;
1033 lprc->top = infoPtr->rcChannel.top;
1035 return 0;
1039 inline static LONG
1040 TRACKBAR_GetNumTics (TRACKBAR_INFO *infoPtr)
1042 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
1043 return 0;
1045 return infoPtr->uNumTics + 2;
1049 static int comp_tics(const void *ap, const void *bp)
1051 const DWORD a = *(const DWORD *)ap;
1052 const DWORD b = *(const DWORD *)bp;
1054 TRACE("(a=%ld, b=%ld)\n", a, b);
1055 if (a < b) return -1;
1056 if (a > b) return 1;
1057 return 0;
1061 inline static LONG
1062 TRACKBAR_GetTic (TRACKBAR_INFO *infoPtr, INT iTic)
1064 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1065 return -1;
1067 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1068 return infoPtr->tics[iTic];
1072 inline static LONG
1073 TRACKBAR_GetTicPos (TRACKBAR_INFO *infoPtr, INT iTic)
1075 LONG range, width, pos, tic;
1076 int offsetthumb;
1078 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1079 return -1;
1081 tic = TRACKBAR_GetTic (infoPtr, iTic);
1082 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1083 if (range <= 0) range = 1;
1084 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1085 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1086 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1088 return pos;
1092 static HWND
1093 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1095 HWND hwndTemp;
1097 if (fLocation) {
1098 /* buddy is left or above */
1099 hwndTemp = infoPtr->hwndBuddyLA;
1100 infoPtr->hwndBuddyLA = hwndBuddy;
1102 else {
1103 /* buddy is right or below */
1104 hwndTemp = infoPtr->hwndBuddyRB;
1105 infoPtr->hwndBuddyRB = hwndBuddy;
1108 TRACKBAR_AlignBuddies (infoPtr);
1110 return hwndTemp;
1114 inline static LONG
1115 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1117 LONG lTemp = infoPtr->lLineSize;
1119 infoPtr->lLineSize = lLineSize;
1121 return lTemp;
1125 inline static LONG
1126 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1128 LONG lTemp = infoPtr->lPageSize;
1130 infoPtr->lPageSize = lPageSize;
1132 return lTemp;
1136 inline static LRESULT
1137 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1139 LONG oldPos = infoPtr->lPos;
1140 infoPtr->lPos = lPosition;
1142 if (infoPtr->lPos < infoPtr->lRangeMin)
1143 infoPtr->lPos = infoPtr->lRangeMin;
1145 if (infoPtr->lPos > infoPtr->lRangeMax)
1146 infoPtr->lPos = infoPtr->lRangeMax;
1147 infoPtr->flags |= TB_THUMBPOSCHANGED;
1149 if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1151 return 0;
1155 inline static LRESULT
1156 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1158 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1159 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1161 if (infoPtr->lPos < infoPtr->lRangeMin) {
1162 infoPtr->lPos = infoPtr->lRangeMin;
1163 infoPtr->flags |= TB_THUMBPOSCHANGED;
1166 if (infoPtr->lPos > infoPtr->lRangeMax) {
1167 infoPtr->lPos = infoPtr->lRangeMax;
1168 infoPtr->flags |= TB_THUMBPOSCHANGED;
1171 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1172 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1174 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1176 return 0;
1180 inline static LRESULT
1181 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1183 infoPtr->lRangeMax = lMax;
1184 if (infoPtr->lPos > infoPtr->lRangeMax) {
1185 infoPtr->lPos = infoPtr->lRangeMax;
1186 infoPtr->flags |= TB_THUMBPOSCHANGED;
1189 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1190 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1192 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1194 return 0;
1198 inline static LRESULT
1199 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1201 infoPtr->lRangeMin = lMin;
1202 if (infoPtr->lPos < infoPtr->lRangeMin) {
1203 infoPtr->lPos = infoPtr->lRangeMin;
1204 infoPtr->flags |= TB_THUMBPOSCHANGED;
1207 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1208 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1210 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1212 return 0;
1216 inline static LRESULT
1217 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1219 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1220 return 0;
1222 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1223 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1224 infoPtr->flags |= TB_SELECTIONCHANGED;
1226 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1227 infoPtr->lSelMin = infoPtr->lRangeMin;
1228 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1229 infoPtr->lSelMax = infoPtr->lRangeMax;
1231 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1233 return 0;
1237 inline static LRESULT
1238 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1240 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1241 return 0;
1243 infoPtr->lSelMax = lEnd;
1244 infoPtr->flags |= TB_SELECTIONCHANGED;
1246 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1247 infoPtr->lSelMax = infoPtr->lRangeMax;
1249 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1251 return 0;
1255 inline static LRESULT
1256 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1258 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1259 return 0;
1261 infoPtr->lSelMin = lStart;
1262 infoPtr->flags |=TB_SELECTIONCHANGED;
1264 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1265 infoPtr->lSelMin = infoPtr->lRangeMin;
1267 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1269 return 0;
1273 inline static LRESULT
1274 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1276 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) {
1277 infoPtr->uThumbLen = iLength;
1278 infoPtr->flags |= TB_THUMBSIZECHANGED;
1279 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1282 return 0;
1286 inline static LRESULT
1287 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1289 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1290 return FALSE;
1292 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1293 return FALSE;
1295 TRACE("lPos=%ld\n", lPos);
1297 infoPtr->uNumTics++;
1298 infoPtr->tics=ReAlloc( infoPtr->tics,
1299 (infoPtr->uNumTics)*sizeof (DWORD));
1300 if (!infoPtr->tics) {
1301 infoPtr->uNumTics = 0;
1302 notify(infoPtr, NM_OUTOFMEMORY);
1303 return FALSE;
1305 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1307 TRACKBAR_InvalidateAll(infoPtr);
1309 return TRUE;
1313 inline static LRESULT
1314 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1316 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1317 infoPtr->uTicFreq = wFreq;
1318 TRACKBAR_RecalculateTics (infoPtr);
1319 TRACKBAR_InvalidateAll(infoPtr);
1322 return 0;
1326 inline static INT
1327 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1329 INT fTemp = infoPtr->fLocation;
1331 infoPtr->fLocation = fLocation;
1333 return fTemp;
1337 inline static LRESULT
1338 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1340 infoPtr->hwndToolTip = hwndTT;
1342 return 0;
1346 inline static BOOL
1347 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1349 BOOL bTemp = infoPtr->bUnicode;
1351 infoPtr->bUnicode = fUnicode;
1353 return bTemp;
1357 static LRESULT
1358 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1360 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1361 RECT rect;
1362 int clientWidth, clientMetric;
1364 /* initial thumb length */
1365 clientMetric = (dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1366 GetClientRect(infoPtr->hwndSelf,&rect);
1367 if (dwStyle & TBS_VERT) {
1368 clientWidth = rect.right - rect.left;
1369 } else {
1370 clientWidth = rect.bottom - rect.top;
1372 if (clientWidth >= clientMetric)
1373 infoPtr->uThumbLen = clientMetric;
1374 else
1375 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1377 TRACKBAR_CalcChannel (infoPtr);
1378 TRACKBAR_UpdateThumb (infoPtr);
1379 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1381 return 0;
1385 static LRESULT
1386 TRACKBAR_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
1388 TRACKBAR_INFO *infoPtr;
1389 DWORD dwStyle;
1391 infoPtr = (TRACKBAR_INFO *)Alloc (sizeof(TRACKBAR_INFO));
1392 if (!infoPtr) return -1;
1393 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1395 /* set default values */
1396 infoPtr->hwndSelf = hwnd;
1397 infoPtr->lRangeMin = 0;
1398 infoPtr->lRangeMax = 100;
1399 infoPtr->lLineSize = 1;
1400 infoPtr->lPageSize = 20;
1401 infoPtr->lSelMin = 0;
1402 infoPtr->lSelMax = 0;
1403 infoPtr->lPos = 0;
1404 infoPtr->fLocation = -1;
1405 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1406 infoPtr->uTicFreq = 1;
1407 infoPtr->tics = NULL;
1408 infoPtr->hwndNotify= lpcs->hwndParent;
1410 TRACKBAR_InitializeThumb (infoPtr);
1412 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1414 /* Create tooltip control */
1415 if (dwStyle & TBS_TOOLTIPS) {
1417 infoPtr->hwndToolTip =
1418 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
1419 CW_USEDEFAULT, CW_USEDEFAULT,
1420 CW_USEDEFAULT, CW_USEDEFAULT,
1421 hwnd, 0, 0, 0);
1423 if (infoPtr->hwndToolTip) {
1424 TTTOOLINFOW ti;
1425 ZeroMemory (&ti, sizeof(ti));
1426 ti.cbSize = sizeof(ti);
1427 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1428 ti.hwnd = hwnd;
1430 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1434 OpenThemeData (hwnd, themeClass);
1436 return 0;
1440 static LRESULT
1441 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1443 /* delete tooltip control */
1444 if (infoPtr->hwndToolTip)
1445 DestroyWindow (infoPtr->hwndToolTip);
1447 Free (infoPtr);
1448 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1449 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1450 return 0;
1454 static LRESULT
1455 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
1457 TRACE("\n");
1458 infoPtr->bFocussed = FALSE;
1459 TRACKBAR_InvalidateAll(infoPtr);
1461 return 0;
1464 static LRESULT
1465 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1467 POINT clickPoint;
1469 clickPoint.x = x;
1470 clickPoint.y = y;
1472 SetFocus(infoPtr->hwndSelf);
1474 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1475 infoPtr->flags |= TB_DRAG_MODE;
1476 SetCapture (infoPtr->hwndSelf);
1477 TRACKBAR_UpdateToolTip (infoPtr);
1478 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1479 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1480 } else {
1481 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1482 if (dir == 0) return 0;
1483 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1484 TRACKBAR_AutoPage (infoPtr, clickPoint);
1485 SetCapture (infoPtr->hwndSelf);
1486 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1489 return 0;
1493 static LRESULT
1494 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1496 if (infoPtr->flags & TB_DRAG_MODE) {
1497 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1498 notify_with_scroll (infoPtr, TB_ENDTRACK);
1499 infoPtr->flags &= ~TB_DRAG_MODE;
1500 ReleaseCapture ();
1501 notify(infoPtr, NM_RELEASEDCAPTURE);
1502 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1503 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1505 if (infoPtr->flags & TB_AUTO_PAGE) {
1506 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1507 infoPtr->flags &= ~TB_AUTO_PAGE;
1508 notify_with_scroll (infoPtr, TB_ENDTRACK);
1509 ReleaseCapture ();
1510 notify(infoPtr, NM_RELEASEDCAPTURE);
1513 return 0;
1517 static LRESULT
1518 TRACKBAR_CaptureChanged (TRACKBAR_INFO *infoPtr)
1520 notify_with_scroll (infoPtr, TB_ENDTRACK);
1521 return 0;
1525 static LRESULT
1526 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1528 if (hdc) {
1529 TRACKBAR_Refresh(infoPtr, hdc);
1530 } else {
1531 PAINTSTRUCT ps;
1532 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1533 TRACKBAR_Refresh (infoPtr, hdc);
1534 EndPaint (infoPtr->hwndSelf, &ps);
1537 return 0;
1541 static LRESULT
1542 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
1544 TRACE("\n");
1545 infoPtr->bFocussed = TRUE;
1546 TRACKBAR_InvalidateAll(infoPtr);
1548 return 0;
1552 static LRESULT
1553 TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
1555 TRACKBAR_InitializeThumb (infoPtr);
1556 TRACKBAR_AlignBuddies (infoPtr);
1558 return 0;
1562 static LRESULT
1563 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, TIMERPROC *tmrpc)
1565 if (infoPtr->flags & TB_AUTO_PAGE) {
1566 POINT pt;
1567 if (GetCursorPos(&pt))
1568 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1569 TRACKBAR_AutoPage(infoPtr, pt);
1571 return 0;
1575 /* update theme after a WM_THEMECHANGED message */
1576 static LRESULT theme_changed (TRACKBAR_INFO* infoPtr)
1578 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1579 CloseThemeData (theme);
1580 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
1581 return 0;
1585 static LRESULT
1586 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1588 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1589 INT clickPlace = (dwStyle & TBS_VERT) ? y : x;
1590 LONG dragPos, oldPos = infoPtr->lPos;
1592 TRACE("(x=%d. y=%d)\n", x, y);
1594 if (infoPtr->flags & TB_AUTO_PAGE) {
1595 POINT pt;
1596 pt.x = x;
1597 pt.y = y;
1598 TRACKBAR_AutoPage (infoPtr, pt);
1599 return TRUE;
1602 if (!(infoPtr->flags & TB_DRAG_MODE))
1604 if (GetWindowTheme (infoPtr->hwndSelf))
1606 DWORD oldFlags = infoPtr->flags;
1607 POINT pt;
1608 pt.x = x;
1609 pt.y = y;
1610 if (PtInRect (&infoPtr->rcThumb, pt))
1612 TRACKMOUSEEVENT tme;
1613 tme.cbSize = sizeof( tme );
1614 tme.dwFlags = TME_LEAVE;
1615 tme.hwndTrack = infoPtr->hwndSelf;
1616 TrackMouseEvent( &tme );
1617 infoPtr->flags |= TB_THUMB_HOT;
1619 else
1621 TRACKMOUSEEVENT tme;
1622 tme.cbSize = sizeof( tme );
1623 tme.dwFlags = TME_CANCEL;
1624 tme.hwndTrack = infoPtr->hwndSelf;
1625 TrackMouseEvent( &tme );
1626 infoPtr->flags &= ~TB_THUMB_HOT;
1628 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1630 return TRUE;
1633 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1634 dwStyle & TBS_VERT);
1635 if (dragPos == oldPos) return TRUE;
1637 infoPtr->lPos = dragPos;
1639 infoPtr->flags |= TB_THUMBPOSCHANGED;
1640 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1643 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1644 UpdateWindow (infoPtr->hwndSelf);
1646 return TRUE;
1649 static BOOL
1650 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1652 DWORD style = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1653 BOOL downIsLeft = style & TBS_DOWNISLEFT;
1654 BOOL vert = style & TBS_VERT;
1655 LONG pos = infoPtr->lPos;
1657 TRACE("%x\n", nVirtKey);
1659 switch (nVirtKey) {
1660 case VK_UP:
1661 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1662 else TRACKBAR_LineUp(infoPtr);
1663 break;
1664 case VK_LEFT:
1665 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1666 else TRACKBAR_LineUp(infoPtr);
1667 break;
1668 case VK_DOWN:
1669 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1670 else TRACKBAR_LineDown(infoPtr);
1671 break;
1672 case VK_RIGHT:
1673 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1674 else TRACKBAR_LineDown(infoPtr);
1675 break;
1676 case VK_NEXT:
1677 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1678 else TRACKBAR_PageDown(infoPtr);
1679 break;
1680 case VK_PRIOR:
1681 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1682 else TRACKBAR_PageUp(infoPtr);
1683 break;
1684 case VK_HOME:
1685 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1686 infoPtr->lPos = infoPtr->lRangeMin;
1687 notify_with_scroll (infoPtr, TB_TOP);
1688 break;
1689 case VK_END:
1690 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1691 infoPtr->lPos = infoPtr->lRangeMax;
1692 notify_with_scroll (infoPtr, TB_BOTTOM);
1693 break;
1696 if (pos != infoPtr->lPos) {
1697 infoPtr->flags |=TB_THUMBPOSCHANGED;
1698 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1701 return TRUE;
1705 inline static BOOL
1706 TRACKBAR_KeyUp (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1708 switch (nVirtKey) {
1709 case VK_LEFT:
1710 case VK_UP:
1711 case VK_RIGHT:
1712 case VK_DOWN:
1713 case VK_NEXT:
1714 case VK_PRIOR:
1715 case VK_HOME:
1716 case VK_END:
1717 notify_with_scroll (infoPtr, TB_ENDTRACK);
1719 return TRUE;
1723 static LRESULT WINAPI
1724 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1726 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1728 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1730 if (!infoPtr && (uMsg != WM_CREATE))
1731 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1733 switch (uMsg)
1735 case TBM_CLEARSEL:
1736 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1738 case TBM_CLEARTICS:
1739 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1741 case TBM_GETBUDDY:
1742 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1744 case TBM_GETCHANNELRECT:
1745 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1747 case TBM_GETLINESIZE:
1748 return infoPtr->lLineSize;
1750 case TBM_GETNUMTICS:
1751 return TRACKBAR_GetNumTics (infoPtr);
1753 case TBM_GETPAGESIZE:
1754 return infoPtr->lPageSize;
1756 case TBM_GETPOS:
1757 return infoPtr->lPos;
1759 case TBM_GETPTICS:
1760 return (LRESULT)infoPtr->tics;
1762 case TBM_GETRANGEMAX:
1763 return infoPtr->lRangeMax;
1765 case TBM_GETRANGEMIN:
1766 return infoPtr->lRangeMin;
1768 case TBM_GETSELEND:
1769 return infoPtr->lSelMax;
1771 case TBM_GETSELSTART:
1772 return infoPtr->lSelMin;
1774 case TBM_GETTHUMBLENGTH:
1775 return infoPtr->uThumbLen;
1777 case TBM_GETTHUMBRECT:
1778 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1780 case TBM_GETTIC:
1781 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1783 case TBM_GETTICPOS:
1784 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1786 case TBM_GETTOOLTIPS:
1787 return (LRESULT)infoPtr->hwndToolTip;
1789 case TBM_GETUNICODEFORMAT:
1790 return infoPtr->bUnicode;
1792 case TBM_SETBUDDY:
1793 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1795 case TBM_SETLINESIZE:
1796 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1798 case TBM_SETPAGESIZE:
1799 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1801 case TBM_SETPOS:
1802 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1804 case TBM_SETRANGE:
1805 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1807 case TBM_SETRANGEMAX:
1808 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1810 case TBM_SETRANGEMIN:
1811 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1813 case TBM_SETSEL:
1814 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1816 case TBM_SETSELEND:
1817 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1819 case TBM_SETSELSTART:
1820 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1822 case TBM_SETTHUMBLENGTH:
1823 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1825 case TBM_SETTIC:
1826 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1828 case TBM_SETTICFREQ:
1829 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1831 case TBM_SETTIPSIDE:
1832 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1834 case TBM_SETTOOLTIPS:
1835 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1837 case TBM_SETUNICODEFORMAT:
1838 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1841 case WM_CAPTURECHANGED:
1842 return TRACKBAR_CaptureChanged (infoPtr);
1844 case WM_CREATE:
1845 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1847 case WM_DESTROY:
1848 return TRACKBAR_Destroy (infoPtr);
1850 /* case WM_ENABLE: */
1852 case WM_ERASEBKGND:
1853 return 0;
1855 case WM_GETDLGCODE:
1856 return DLGC_WANTARROWS;
1858 case WM_KEYDOWN:
1859 return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
1861 case WM_KEYUP:
1862 return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
1864 case WM_KILLFOCUS:
1865 return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
1867 case WM_LBUTTONDOWN:
1868 return TRACKBAR_LButtonDown (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1870 case WM_LBUTTONUP:
1871 return TRACKBAR_LButtonUp (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1873 case WM_MOUSELEAVE:
1874 infoPtr->flags &= ~TB_THUMB_HOT;
1875 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1876 return 0;
1878 case WM_MOUSEMOVE:
1879 return TRACKBAR_MouseMove (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1881 case WM_PRINTCLIENT:
1882 case WM_PAINT:
1883 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1885 case WM_SETFOCUS:
1886 return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
1888 case WM_SIZE:
1889 return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
1891 case WM_THEMECHANGED:
1892 return theme_changed (infoPtr);
1894 case WM_TIMER:
1895 return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
1897 case WM_WININICHANGE:
1898 return TRACKBAR_InitializeThumb (infoPtr);
1900 default:
1901 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1902 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
1903 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1908 void TRACKBAR_Register (void)
1910 WNDCLASSW wndClass;
1912 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1913 wndClass.style = CS_GLOBALCLASS;
1914 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1915 wndClass.cbClsExtra = 0;
1916 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1917 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1918 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1919 wndClass.lpszClassName = TRACKBAR_CLASSW;
1921 RegisterClassW (&wndClass);
1925 void TRACKBAR_Unregister (void)
1927 UnregisterClassW (TRACKBAR_CLASSW, NULL);