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
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.
46 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
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 */
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 };
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)
117 TRACE("(code=%d)\n", code);
119 pnmh->hwndFrom = infoPtr->hwndSelf;
120 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
122 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
123 (WPARAM)pnmh->idFrom, (LPARAM)pnmh);
125 TRACE(" <= %ld\n", result);
130 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
133 return notify_hdr(infoPtr, code, &nmh);
137 notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
139 BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT;
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)
152 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin)
153 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
156 Free (infoPtr->tics);
157 infoPtr->tics = NULL;
158 infoPtr->uNumTics = 0;
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);
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) */
182 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place, int vertical)
184 double range, width, pos, offsetthumb;
186 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
188 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
189 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
190 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
192 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
193 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
194 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
196 pos += infoPtr->lRangeMin;
197 if (pos > infoPtr->lRangeMax)
198 pos = infoPtr->lRangeMax;
199 else if (pos < infoPtr->lRangeMin)
200 pos = infoPtr->lRangeMin;
202 TRACE("%.2f\n", pos);
203 return (LONG)(pos + 0.5);
207 /* return: 0> prev, 0 none, >0 next */
209 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
211 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
214 if (dwStyle & TBS_VERT) {
215 pageRect.top = infoPtr->rcChannel.top;
216 pageRect.bottom = infoPtr->rcChannel.bottom;
217 pageRect.left = infoPtr->rcThumb.left;
218 pageRect.right = infoPtr->rcThumb.right;
220 pageRect.top = infoPtr->rcThumb.top;
221 pageRect.bottom = infoPtr->rcThumb.bottom;
222 pageRect.left = infoPtr->rcChannel.left;
223 pageRect.right = infoPtr->rcChannel.right;
227 if (PtInRect(&pageRect, clickPoint))
229 int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
231 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace,
233 return clickPos - infoPtr->lPos;
240 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
242 if (infoPtr->lPos == infoPtr->lRangeMax) return;
244 infoPtr->lPos += infoPtr->lPageSize;
245 if (infoPtr->lPos > infoPtr->lRangeMax)
246 infoPtr->lPos = infoPtr->lRangeMax;
247 notify_with_scroll (infoPtr, TB_PAGEDOWN);
252 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
254 if (infoPtr->lPos == infoPtr->lRangeMin) return;
256 infoPtr->lPos -= infoPtr->lPageSize;
257 if (infoPtr->lPos < infoPtr->lRangeMin)
258 infoPtr->lPos = infoPtr->lRangeMin;
259 notify_with_scroll (infoPtr, TB_PAGEUP);
262 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
264 if (infoPtr->lPos == infoPtr->lRangeMin) return;
265 infoPtr->lPos -= infoPtr->lLineSize;
266 if (infoPtr->lPos < infoPtr->lRangeMin)
267 infoPtr->lPos = infoPtr->lRangeMin;
268 notify_with_scroll (infoPtr, TB_LINEUP);
271 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
273 if (infoPtr->lPos == infoPtr->lRangeMax) return;
274 infoPtr->lPos += infoPtr->lLineSize;
275 if (infoPtr->lPos > infoPtr->lRangeMax)
276 infoPtr->lPos = infoPtr->lRangeMax;
277 notify_with_scroll (infoPtr, TB_LINEDOWN);
281 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
283 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
284 INT cyChannel, offsetthumb, offsetedge;
285 RECT lpRect, *channel = & infoPtr->rcChannel;
287 GetClientRect (infoPtr->hwndSelf, &lpRect);
289 offsetthumb = infoPtr->uThumbLen / 4;
290 offsetedge = offsetthumb + 3;
291 cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
292 if (dwStyle & TBS_VERT) {
293 channel->top = lpRect.top + offsetedge;
294 channel->bottom = lpRect.bottom - offsetedge;
295 if (dwStyle & TBS_ENABLESELRANGE)
296 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
298 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
299 if (dwStyle & TBS_BOTH) {
300 if (dwStyle & TBS_NOTICKS)
305 else if (dwStyle & TBS_TOP) {
306 if (dwStyle & TBS_NOTICKS)
311 channel->right = channel->left + cyChannel;
313 channel->left = lpRect.left + offsetedge;
314 channel->right = lpRect.right - offsetedge;
315 if (dwStyle & TBS_ENABLESELRANGE)
316 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
318 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
319 if (dwStyle & TBS_BOTH) {
320 if (dwStyle & TBS_NOTICKS)
325 else if (dwStyle & TBS_TOP) {
326 if (dwStyle & TBS_NOTICKS)
331 channel->bottom = channel->top + cyChannel;
336 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
338 int range, width, height, thumbwidth;
339 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
342 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
343 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
345 if (!range) range = 1;
347 GetClientRect(infoPtr->hwndSelf, &lpRect);
348 if (dwStyle & TBS_VERT)
350 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
352 if ((dwStyle & (TBS_BOTH | TBS_LEFT)) && !(dwStyle & TBS_NOTICKS))
356 thumb->right = thumb->left + infoPtr->uThumbLen;
357 thumb->top = infoPtr->rcChannel.top +
358 (height*(lPos - infoPtr->lRangeMin))/range;
359 thumb->bottom = thumb->top + thumbwidth;
363 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
365 thumb->left = infoPtr->rcChannel.left +
366 (width*(lPos - infoPtr->lRangeMin))/range;
367 thumb->right = thumb->left + thumbwidth;
368 if ((dwStyle & (TBS_BOTH | TBS_TOP)) && !(dwStyle & TBS_NOTICKS))
372 thumb->bottom = thumb->top + infoPtr->uThumbLen;
377 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
379 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
383 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
385 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
389 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
393 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
394 InflateRect(&rcThumb, 1, 1);
395 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
399 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
401 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
402 if (newPos != oldPos)
403 TRACKBAR_InvalidateThumb (infoPtr, newPos);
407 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
409 return infoPtr->lSelMin != infoPtr->lSelMax;
413 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
415 RECT *selection = &infoPtr->rcSelection;
416 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
417 int offsetthumb, height, width;
420 SetRectEmpty (selection);
422 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) {
423 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
424 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
425 selection->top = infoPtr->rcChannel.top + offsetthumb +
426 (height*infoPtr->lSelMin)/range;
427 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
428 (height*infoPtr->lSelMax)/range;
429 selection->left = infoPtr->rcChannel.left + 3;
430 selection->right = infoPtr->rcChannel.right - 3;
432 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
433 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
434 selection->left = infoPtr->rcChannel.left + offsetthumb +
435 (width*infoPtr->lSelMin)/range;
436 selection->right = infoPtr->rcChannel.left + offsetthumb +
437 (width*infoPtr->lSelMax)/range;
438 selection->top = infoPtr->rcChannel.top + 3;
439 selection->bottom = infoPtr->rcChannel.bottom - 3;
443 TRACE("selection[left=%d, top=%d, right=%d, bottom=%d]\n",
444 selection->left, selection->top, selection->right, selection->bottom);
448 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
450 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
451 LONG prevPos = infoPtr->lPos;
453 TRACE("x=%d, y=%d, dir=%d\n", clickPoint.x, clickPoint.y, dir);
455 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
456 TRACKBAR_PageDown(infoPtr);
457 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
458 TRACKBAR_PageUp(infoPtr);
461 infoPtr->flags |= TB_THUMBPOSCHANGED;
462 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
467 /* Trackbar drawing code. I like my spaghetti done milanese. */
470 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
472 RECT rcChannel = infoPtr->rcChannel;
473 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
477 DrawThemeBackground (theme, hdc,
478 (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) ?
479 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
483 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
484 if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
485 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
486 if (TRACKBAR_HasSelection(infoPtr))
487 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
493 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
495 int x, y, ox, oy, range, side, indent = 0, len = 3;
499 if (flags & TBS_VERT) {
500 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
501 rcTics.left = infoPtr->rcThumb.left - 2;
502 rcTics.right = infoPtr->rcThumb.right + 2;
503 rcTics.top = infoPtr->rcChannel.top + offsetthumb + 1;
504 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb;
506 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
507 rcTics.left = infoPtr->rcChannel.left + offsetthumb + 1;
508 rcTics.right = infoPtr->rcChannel.right - offsetthumb;
509 rcTics.top = infoPtr->rcThumb.top - 2;
510 rcTics.bottom = infoPtr->rcThumb.bottom + 2;
513 if (flags & (TBS_TOP | TBS_LEFT)) {
523 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
525 range = 1; /* to avoid division by zero */
527 if (flags & TIC_SELECTIONMARK) {
528 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
529 } else if (flags & TIC_EDGE) {
533 if (flags & TBS_VERT) {
534 int height = rcTics.bottom - rcTics.top;
535 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
537 int width = rcTics.right - rcTics.left;
538 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
543 MoveToEx(hdc, x, y, 0);
544 if (flags & TBS_VERT) x += len * side;
545 else y += len * side;
548 if (flags & TIC_SELECTIONMARK) {
549 if (flags & TBS_VERT) {
554 MoveToEx(hdc, x, y, 0);
555 if (flags & TBS_VERT) {
568 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
570 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
571 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
573 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
574 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
578 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
581 int ticFlags = dwStyle & 0x0f;
582 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
583 HPEN hOldPen, hTicPen;
584 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
588 int part = (dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
589 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
591 /* create the pen to draw the tics with */
592 hTicPen = CreatePenIndirect(&ticPen);
593 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
595 /* actually draw the tics */
596 for (i=0; i<infoPtr->uNumTics; i++)
597 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
599 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
600 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
602 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
603 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
604 ticFlags | TIC_SELECTIONMARKMIN);
605 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
606 ticFlags | TIC_SELECTIONMARKMAX);
609 /* clean up the pen, if we created one */
611 SelectObject(hdc, hOldPen);
612 DeleteObject(hTicPen);
617 TRACKBAR_DrawThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
621 RECT thumb = infoPtr->rcThumb;
627 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
633 if (dwStyle & TBS_BOTH)
634 partId = (dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
635 else if (dwStyle & TBS_LEFT)
636 partId = (dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
638 partId = (dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
640 if (dwStyle & WS_DISABLED)
641 stateId = TUS_DISABLED;
642 else if (infoPtr->flags & TB_DRAG_MODE)
643 stateId = TUS_PRESSED;
644 else if (infoPtr->flags & TB_THUMB_HOT)
647 stateId = TUS_NORMAL;
649 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
654 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
655 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
656 SetPolyFillMode (hdc, WINDING);
658 if (dwStyle & TBS_BOTH)
660 points[0].x=thumb.right;
661 points[0].y=thumb.top;
662 points[1].x=thumb.right;
663 points[1].y=thumb.bottom;
664 points[2].x=thumb.left;
665 points[2].y=thumb.bottom;
666 points[3].x=thumb.left;
667 points[3].y=thumb.top;
668 points[4].x=points[0].x;
669 points[4].y=points[0].y;
675 if (dwStyle & TBS_VERT)
677 PointDepth = (thumb.bottom - thumb.top) / 2;
678 if (dwStyle & TBS_LEFT)
680 points[0].x=thumb.right;
681 points[0].y=thumb.top;
682 points[1].x=thumb.right;
683 points[1].y=thumb.bottom;
684 points[2].x=thumb.left + PointDepth;
685 points[2].y=thumb.bottom;
686 points[3].x=thumb.left;
687 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
688 points[4].x=thumb.left + PointDepth;
689 points[4].y=thumb.top;
690 points[5].x=points[0].x;
691 points[5].y=points[0].y;
696 points[0].x=thumb.right;
697 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
698 points[1].x=thumb.right - PointDepth;
699 points[1].y=thumb.bottom;
700 points[2].x=thumb.left;
701 points[2].y=thumb.bottom;
702 points[3].x=thumb.left;
703 points[3].y=thumb.top;
704 points[4].x=thumb.right - PointDepth;
705 points[4].y=thumb.top;
706 points[5].x=points[0].x;
707 points[5].y=points[0].y;
712 PointDepth = (thumb.right - thumb.left) / 2;
713 if (dwStyle & TBS_TOP)
715 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
716 points[0].y=thumb.top;
717 points[1].x=thumb.right;
718 points[1].y=thumb.top + PointDepth;
719 points[2].x=thumb.right;
720 points[2].y=thumb.bottom;
721 points[3].x=thumb.left;
722 points[3].y=thumb.bottom;
723 points[4].x=thumb.left;
724 points[4].y=thumb.top + PointDepth;
725 points[5].x=points[0].x;
726 points[5].y=points[0].y;
731 points[0].x=thumb.right;
732 points[0].y=thumb.top;
733 points[1].x=thumb.right;
734 points[1].y=thumb.bottom - PointDepth;
735 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
736 points[2].y=thumb.bottom;
737 points[3].x=thumb.left;
738 points[3].y=thumb.bottom - PointDepth;
739 points[4].x=thumb.left;
740 points[4].y=thumb.top;
741 points[5].x=points[0].x;
742 points[5].y=points[0].y;
748 /* Draw the thumb now */
749 Polygon (hdc, points, PointCount);
750 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
751 Polyline(hdc,points, BlackUntil);
752 SelectObject(hdc, GetStockObject(WHITE_PEN));
753 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
754 SelectObject(hdc, oldpen);
755 SelectObject(hdc, oldbr);
760 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
764 if (!infoPtr->hwndToolTip) return;
766 ZeroMemory(&ti, sizeof(ti));
767 ti.cbSize = sizeof(ti);
768 ti.hwnd = infoPtr->hwndSelf;
770 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
775 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
777 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
779 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
785 if (!infoPtr->hwndToolTip) return;
787 ZeroMemory(&ti, sizeof(ti));
788 ti.cbSize = sizeof(ti);
789 ti.hwnd = infoPtr->hwndSelf;
790 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
792 wsprintfW (buf, fmt, infoPtr->lPos);
794 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
796 GetClientRect (infoPtr->hwndSelf, &rcClient);
797 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
798 if (dwStyle & TBS_VERT) {
799 if (infoPtr->fLocation == TBTS_LEFT)
800 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
802 pt.x = rcClient.right + TOOLTIP_OFFSET;
803 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
805 if (infoPtr->fLocation == TBTS_TOP)
806 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
808 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
809 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
811 ClientToScreen(infoPtr->hwndSelf, &pt);
813 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
814 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
819 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
821 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
824 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
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);
847 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
849 hOldBmp = SelectObject(hdc, hOffScreenBmp);
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;
864 /* start the paint cycle */
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 ((theme = GetWindowTheme (infoPtr->hwndSelf))) {
873 DrawThemeBackground (theme, hdc,
874 (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) ?
875 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcClient, 0);
876 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, &rcClient);
879 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
880 if (gcdrf != CDRF_DODEFAULT)
881 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
885 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
886 nmcd.dwItemSpec = TBCD_CHANNEL;
887 nmcd.uItemState = CDIS_DEFAULT;
888 nmcd.rc = infoPtr->rcChannel;
889 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
890 } else icdrf = CDRF_DODEFAULT;
891 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
892 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
893 if (icdrf & CDRF_NOTIFYPOSTPAINT)
894 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
899 if (!(dwStyle & TBS_NOTICKS)) {
900 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
901 nmcd.dwItemSpec = TBCD_TICS;
902 nmcd.uItemState = CDIS_DEFAULT;
904 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
905 } else icdrf = CDRF_DODEFAULT;
906 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
907 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
908 if (icdrf & CDRF_NOTIFYPOSTPAINT)
909 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
914 if (!(dwStyle & TBS_NOTHUMB)) {
915 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
916 nmcd.dwItemSpec = TBCD_THUMB;
917 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
918 nmcd.rc = infoPtr->rcThumb;
919 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
920 } else icdrf = CDRF_DODEFAULT;
921 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
922 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
923 if (icdrf & CDRF_NOTIFYPOSTPAINT)
924 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
928 /* draw focus rectangle */
929 if (infoPtr->bFocussed) {
930 DrawFocusRect(hdc, &rcClient);
933 /* finish up the painting */
934 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
935 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
938 /* cleanup, if we rendered offscreen */
940 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
941 SelectObject(hdc, hOldBmp);
942 DeleteObject(hOffScreenBmp);
949 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
951 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
952 HWND hwndParent = GetParent (infoPtr->hwndSelf);
953 RECT rcSelf, rcBuddy;
956 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
957 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
959 /* align buddy left or above */
960 if (infoPtr->hwndBuddyLA) {
961 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
962 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
964 if (dwStyle & TBS_VERT) {
965 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
966 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
967 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
970 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
971 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
972 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
975 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
976 SWP_NOZORDER | SWP_NOSIZE);
980 /* align buddy right or below */
981 if (infoPtr->hwndBuddyRB) {
982 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
983 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
985 if (dwStyle & TBS_VERT) {
986 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
987 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
992 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
993 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
995 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
996 SWP_NOZORDER | SWP_NOSIZE);
1002 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1004 infoPtr->lSelMin = 0;
1005 infoPtr->lSelMax = 0;
1006 infoPtr->flags |= TB_SELECTIONCHANGED;
1008 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1015 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1017 if (infoPtr->tics) {
1018 Free (infoPtr->tics);
1019 infoPtr->tics = NULL;
1020 infoPtr->uNumTics = 0;
1023 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1029 static inline LRESULT
1030 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1032 if (lprc == NULL) return 0;
1034 lprc->left = infoPtr->rcChannel.left;
1035 lprc->right = infoPtr->rcChannel.right;
1036 lprc->bottom = infoPtr->rcChannel.bottom;
1037 lprc->top = infoPtr->rcChannel.top;
1044 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1046 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
1049 if(infoPtr->uNumTics == 0)
1052 return infoPtr->uNumTics + 1;
1056 static int comp_tics (const void *ap, const void *bp)
1058 const DWORD a = *(const DWORD *)ap;
1059 const DWORD b = *(const DWORD *)bp;
1061 TRACE("(a=%d, b=%d)\n", a, b);
1062 if (a < b) return -1;
1063 if (a > b) return 1;
1069 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1071 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1074 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1075 return infoPtr->tics[iTic];
1080 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1082 LONG range, width, pos, tic;
1085 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1088 tic = TRACKBAR_GetTic (infoPtr, iTic);
1089 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1090 if (range <= 0) range = 1;
1091 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1092 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1093 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1100 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1105 /* buddy is left or above */
1106 hwndTemp = infoPtr->hwndBuddyLA;
1107 infoPtr->hwndBuddyLA = hwndBuddy;
1110 /* buddy is right or below */
1111 hwndTemp = infoPtr->hwndBuddyRB;
1112 infoPtr->hwndBuddyRB = hwndBuddy;
1115 TRACKBAR_AlignBuddies (infoPtr);
1122 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1124 LONG lTemp = infoPtr->lLineSize;
1126 infoPtr->lLineSize = lLineSize;
1133 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1135 LONG lTemp = infoPtr->lPageSize;
1137 infoPtr->lPageSize = lPageSize;
1143 static inline LRESULT
1144 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1146 LONG oldPos = infoPtr->lPos;
1147 infoPtr->lPos = lPosition;
1149 if (infoPtr->lPos < infoPtr->lRangeMin)
1150 infoPtr->lPos = infoPtr->lRangeMin;
1152 if (infoPtr->lPos > infoPtr->lRangeMax)
1153 infoPtr->lPos = infoPtr->lRangeMax;
1154 infoPtr->flags |= TB_THUMBPOSCHANGED;
1156 if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1162 static inline LRESULT
1163 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1165 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1166 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1168 if (infoPtr->lPos < infoPtr->lRangeMin) {
1169 infoPtr->lPos = infoPtr->lRangeMin;
1170 infoPtr->flags |= TB_THUMBPOSCHANGED;
1173 if (infoPtr->lPos > infoPtr->lRangeMax) {
1174 infoPtr->lPos = infoPtr->lRangeMax;
1175 infoPtr->flags |= TB_THUMBPOSCHANGED;
1178 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1179 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1181 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1187 static inline LRESULT
1188 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1190 infoPtr->lRangeMax = lMax;
1191 if (infoPtr->lPos > infoPtr->lRangeMax) {
1192 infoPtr->lPos = infoPtr->lRangeMax;
1193 infoPtr->flags |= TB_THUMBPOSCHANGED;
1196 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1197 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1199 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1205 static inline LRESULT
1206 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1208 infoPtr->lRangeMin = lMin;
1209 if (infoPtr->lPos < infoPtr->lRangeMin) {
1210 infoPtr->lPos = infoPtr->lRangeMin;
1211 infoPtr->flags |= TB_THUMBPOSCHANGED;
1214 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1215 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1217 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1223 static inline LRESULT
1224 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1226 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1227 infoPtr->lSelMin = 0;
1228 infoPtr->lSelMax = 0;
1232 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1233 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1234 infoPtr->flags |= TB_SELECTIONCHANGED;
1236 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1237 infoPtr->lSelMin = infoPtr->lRangeMin;
1238 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1239 infoPtr->lSelMax = infoPtr->lRangeMax;
1241 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1247 static inline LRESULT
1248 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1250 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1251 infoPtr->lSelMax = 0;
1255 infoPtr->lSelMax = lEnd;
1256 infoPtr->flags |= TB_SELECTIONCHANGED;
1258 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1259 infoPtr->lSelMax = infoPtr->lRangeMax;
1261 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1267 static inline LRESULT
1268 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1270 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1271 infoPtr->lSelMin = 0;
1275 infoPtr->lSelMin = lStart;
1276 infoPtr->flags |=TB_SELECTIONCHANGED;
1278 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1279 infoPtr->lSelMin = infoPtr->lRangeMin;
1281 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1287 static inline LRESULT
1288 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1290 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) {
1291 infoPtr->uThumbLen = iLength;
1292 infoPtr->flags |= TB_THUMBSIZECHANGED;
1293 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1300 static inline LRESULT
1301 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1303 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1306 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1309 TRACE("lPos=%d\n", lPos);
1311 infoPtr->uNumTics++;
1312 infoPtr->tics=ReAlloc( infoPtr->tics,
1313 (infoPtr->uNumTics)*sizeof (DWORD));
1314 if (!infoPtr->tics) {
1315 infoPtr->uNumTics = 0;
1316 notify(infoPtr, NM_OUTOFMEMORY);
1319 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1321 TRACKBAR_InvalidateAll(infoPtr);
1327 static inline LRESULT
1328 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1330 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1331 infoPtr->uTicFreq = wFreq;
1332 TRACKBAR_RecalculateTics (infoPtr);
1333 TRACKBAR_InvalidateAll(infoPtr);
1341 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1343 INT fTemp = infoPtr->fLocation;
1345 infoPtr->fLocation = fLocation;
1351 static inline LRESULT
1352 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1354 infoPtr->hwndToolTip = hwndTT;
1361 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1363 BOOL bTemp = infoPtr->bUnicode;
1365 infoPtr->bUnicode = fUnicode;
1372 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1374 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1376 int clientWidth, clientMetric;
1378 /* initial thumb length */
1379 clientMetric = (dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1380 GetClientRect(infoPtr->hwndSelf,&rect);
1381 if (dwStyle & TBS_VERT) {
1382 clientWidth = rect.right - rect.left;
1384 clientWidth = rect.bottom - rect.top;
1386 if (clientWidth >= clientMetric)
1387 infoPtr->uThumbLen = clientMetric;
1389 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1391 TRACKBAR_CalcChannel (infoPtr);
1392 TRACKBAR_UpdateThumb (infoPtr);
1393 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1400 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1402 TRACKBAR_INFO *infoPtr;
1405 infoPtr = (TRACKBAR_INFO *)Alloc (sizeof(TRACKBAR_INFO));
1406 if (!infoPtr) return -1;
1407 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1409 /* set default values */
1410 infoPtr->hwndSelf = hwnd;
1411 infoPtr->lRangeMin = 0;
1412 infoPtr->lRangeMax = 100;
1413 infoPtr->lLineSize = 1;
1414 infoPtr->lPageSize = 20;
1415 infoPtr->lSelMin = 0;
1416 infoPtr->lSelMax = 0;
1418 infoPtr->fLocation = -1;
1419 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1420 infoPtr->uTicFreq = 1;
1421 infoPtr->tics = NULL;
1422 infoPtr->hwndNotify= lpcs->hwndParent;
1424 TRACKBAR_InitializeThumb (infoPtr);
1426 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1428 /* Create tooltip control */
1429 if (dwStyle & TBS_TOOLTIPS) {
1431 infoPtr->hwndToolTip =
1432 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1433 CW_USEDEFAULT, CW_USEDEFAULT,
1434 CW_USEDEFAULT, CW_USEDEFAULT,
1437 if (infoPtr->hwndToolTip) {
1439 ZeroMemory (&ti, sizeof(ti));
1440 ti.cbSize = sizeof(ti);
1441 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1444 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1448 OpenThemeData (hwnd, themeClass);
1455 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1457 /* delete tooltip control */
1458 if (infoPtr->hwndToolTip)
1459 DestroyWindow (infoPtr->hwndToolTip);
1462 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1463 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1469 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
1472 infoPtr->bFocussed = FALSE;
1473 TRACKBAR_InvalidateAll(infoPtr);
1479 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1486 SetFocus(infoPtr->hwndSelf);
1488 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1489 infoPtr->flags |= TB_DRAG_MODE;
1490 SetCapture (infoPtr->hwndSelf);
1491 TRACKBAR_UpdateToolTip (infoPtr);
1492 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1493 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1495 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1496 if (dir == 0) return 0;
1497 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1498 TRACKBAR_AutoPage (infoPtr, clickPoint);
1499 SetCapture (infoPtr->hwndSelf);
1500 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1508 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1510 if (infoPtr->flags & TB_DRAG_MODE) {
1511 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1512 notify_with_scroll (infoPtr, TB_ENDTRACK);
1513 infoPtr->flags &= ~TB_DRAG_MODE;
1515 notify(infoPtr, NM_RELEASEDCAPTURE);
1516 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1517 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1519 if (infoPtr->flags & TB_AUTO_PAGE) {
1520 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1521 infoPtr->flags &= ~TB_AUTO_PAGE;
1522 notify_with_scroll (infoPtr, TB_ENDTRACK);
1524 notify(infoPtr, NM_RELEASEDCAPTURE);
1532 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1534 notify_with_scroll (infoPtr, TB_ENDTRACK);
1540 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1543 TRACKBAR_Refresh(infoPtr, hdc);
1546 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1547 TRACKBAR_Refresh (infoPtr, hdc);
1548 EndPaint (infoPtr->hwndSelf, &ps);
1556 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
1559 infoPtr->bFocussed = TRUE;
1560 TRACKBAR_InvalidateAll(infoPtr);
1567 TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
1569 TRACKBAR_InitializeThumb (infoPtr);
1570 TRACKBAR_AlignBuddies (infoPtr);
1577 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, const TIMERPROC *tmrpc)
1579 if (infoPtr->flags & TB_AUTO_PAGE) {
1581 if (GetCursorPos(&pt))
1582 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1583 TRACKBAR_AutoPage(infoPtr, pt);
1589 /* update theme after a WM_THEMECHANGED message */
1590 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1592 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1593 CloseThemeData (theme);
1594 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
1600 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1602 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1603 INT clickPlace = (dwStyle & TBS_VERT) ? y : x;
1604 LONG dragPos, oldPos = infoPtr->lPos;
1606 TRACE("(x=%d. y=%d)\n", x, y);
1608 if (infoPtr->flags & TB_AUTO_PAGE) {
1612 TRACKBAR_AutoPage (infoPtr, pt);
1616 if (!(infoPtr->flags & TB_DRAG_MODE))
1618 if (GetWindowTheme (infoPtr->hwndSelf))
1620 DWORD oldFlags = infoPtr->flags;
1624 if (PtInRect (&infoPtr->rcThumb, pt))
1626 TRACKMOUSEEVENT tme;
1627 tme.cbSize = sizeof( tme );
1628 tme.dwFlags = TME_LEAVE;
1629 tme.hwndTrack = infoPtr->hwndSelf;
1630 TrackMouseEvent( &tme );
1631 infoPtr->flags |= TB_THUMB_HOT;
1635 TRACKMOUSEEVENT tme;
1636 tme.cbSize = sizeof( tme );
1637 tme.dwFlags = TME_CANCEL;
1638 tme.hwndTrack = infoPtr->hwndSelf;
1639 TrackMouseEvent( &tme );
1640 infoPtr->flags &= ~TB_THUMB_HOT;
1642 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1647 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1648 dwStyle & TBS_VERT);
1649 if (dragPos == oldPos) return TRUE;
1651 infoPtr->lPos = dragPos;
1653 infoPtr->flags |= TB_THUMBPOSCHANGED;
1654 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1657 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1658 UpdateWindow (infoPtr->hwndSelf);
1664 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1666 DWORD style = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1667 BOOL downIsLeft = style & TBS_DOWNISLEFT;
1668 BOOL vert = style & TBS_VERT;
1669 LONG pos = infoPtr->lPos;
1671 TRACE("%x\n", nVirtKey);
1675 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1676 else TRACKBAR_LineUp(infoPtr);
1679 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1680 else TRACKBAR_LineUp(infoPtr);
1683 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1684 else TRACKBAR_LineDown(infoPtr);
1687 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1688 else TRACKBAR_LineDown(infoPtr);
1691 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1692 else TRACKBAR_PageDown(infoPtr);
1695 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1696 else TRACKBAR_PageUp(infoPtr);
1699 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1700 infoPtr->lPos = infoPtr->lRangeMin;
1701 notify_with_scroll (infoPtr, TB_TOP);
1704 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1705 infoPtr->lPos = infoPtr->lRangeMax;
1706 notify_with_scroll (infoPtr, TB_BOTTOM);
1710 if (pos != infoPtr->lPos) {
1711 infoPtr->flags |=TB_THUMBPOSCHANGED;
1712 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1720 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1731 notify_with_scroll (infoPtr, TB_ENDTRACK);
1737 static LRESULT WINAPI
1738 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1740 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1742 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1744 if (!infoPtr && (uMsg != WM_CREATE))
1745 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1750 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1753 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1756 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1758 case TBM_GETCHANNELRECT:
1759 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1761 case TBM_GETLINESIZE:
1762 return infoPtr->lLineSize;
1764 case TBM_GETNUMTICS:
1765 return TRACKBAR_GetNumTics (infoPtr);
1767 case TBM_GETPAGESIZE:
1768 return infoPtr->lPageSize;
1771 return infoPtr->lPos;
1774 return (LRESULT)infoPtr->tics;
1776 case TBM_GETRANGEMAX:
1777 return infoPtr->lRangeMax;
1779 case TBM_GETRANGEMIN:
1780 return infoPtr->lRangeMin;
1783 return infoPtr->lSelMax;
1785 case TBM_GETSELSTART:
1786 return infoPtr->lSelMin;
1788 case TBM_GETTHUMBLENGTH:
1789 return infoPtr->uThumbLen;
1791 case TBM_GETTHUMBRECT:
1792 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1795 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1798 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1800 case TBM_GETTOOLTIPS:
1801 return (LRESULT)infoPtr->hwndToolTip;
1803 case TBM_GETUNICODEFORMAT:
1804 return infoPtr->bUnicode;
1807 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1809 case TBM_SETLINESIZE:
1810 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1812 case TBM_SETPAGESIZE:
1813 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1816 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1819 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1821 case TBM_SETRANGEMAX:
1822 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1824 case TBM_SETRANGEMIN:
1825 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1828 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1831 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1833 case TBM_SETSELSTART:
1834 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1836 case TBM_SETTHUMBLENGTH:
1837 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1840 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1842 case TBM_SETTICFREQ:
1843 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1845 case TBM_SETTIPSIDE:
1846 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1848 case TBM_SETTOOLTIPS:
1849 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1851 case TBM_SETUNICODEFORMAT:
1852 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1855 case WM_CAPTURECHANGED:
1856 return TRACKBAR_CaptureChanged (infoPtr);
1859 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1862 return TRACKBAR_Destroy (infoPtr);
1864 /* case WM_ENABLE: */
1870 return DLGC_WANTARROWS;
1873 return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
1876 return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
1879 return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
1881 case WM_LBUTTONDOWN:
1882 return TRACKBAR_LButtonDown (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1885 return TRACKBAR_LButtonUp (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1888 infoPtr->flags &= ~TB_THUMB_HOT;
1889 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1893 return TRACKBAR_MouseMove (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1895 case WM_PRINTCLIENT:
1897 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1900 return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
1903 return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
1905 case WM_THEMECHANGED:
1906 return theme_changed (infoPtr);
1909 return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
1911 case WM_WININICHANGE:
1912 return TRACKBAR_InitializeThumb (infoPtr);
1915 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1916 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
1917 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1922 void TRACKBAR_Register (void)
1926 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1927 wndClass.style = CS_GLOBALCLASS;
1928 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1929 wndClass.cbClsExtra = 0;
1930 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1931 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1932 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1933 wndClass.lpszClassName = TRACKBAR_CLASSW;
1935 RegisterClassW (&wndClass);
1939 void TRACKBAR_Unregister (void)
1941 UnregisterClassW (TRACKBAR_CLASSW, NULL);