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);
80 #define TB_REFRESH_TIMER 1
81 #define TB_REFRESH_DELAY 500
83 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
85 #define TB_DEFAULTPAGESIZE 20
87 /* Used by TRACKBAR_Refresh to find out which parts of the control
88 need to be recalculated */
90 #define TB_THUMBPOSCHANGED 1
91 #define TB_THUMBSIZECHANGED 2
92 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
93 #define TB_SELECTIONCHANGED 4
94 #define TB_DRAG_MODE 8 /* we're dragging the slider */
95 #define TB_AUTO_PAGE_LEFT 16
96 #define TB_AUTO_PAGE_RIGHT 32
97 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
98 #define TB_THUMB_HOT 64 /* mouse hovers above thumb */
100 /* helper defines for TRACKBAR_DrawTic */
101 #define TIC_EDGE 0x20
102 #define TIC_SELECTIONMARKMAX 0x80
103 #define TIC_SELECTIONMARKMIN 0x100
104 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
106 static const WCHAR themeClass[] = { 'T','r','a','c','k','b','a','r',0 };
109 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
111 pnmcd->dwDrawStage = stage;
112 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
113 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
116 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
120 TRACE("(code=%d)\n", code);
122 pnmh->hwndFrom = infoPtr->hwndSelf;
123 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
125 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
127 TRACE(" <= %ld\n", result);
132 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
135 return notify_hdr(infoPtr, code, &nmh);
138 static void notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
140 UINT scroll = infoPtr->dwStyle & TBS_VERT ? WM_VSCROLL : WM_HSCROLL;
144 SendMessageW (infoPtr->hwndNotify, scroll, code, (LPARAM)infoPtr->hwndSelf);
147 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
152 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin) {
153 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
154 /* don't add extra tic if there's no remainder */
155 if (nrTics && ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0))
159 Free (infoPtr->tics);
160 infoPtr->tics = NULL;
161 infoPtr->uNumTics = 0;
165 if (nrTics != infoPtr->uNumTics) {
166 infoPtr->tics=ReAlloc (infoPtr->tics,
167 (nrTics+1)*sizeof (DWORD));
168 if (!infoPtr->tics) {
169 infoPtr->uNumTics = 0;
170 notify(infoPtr, NM_OUTOFMEMORY);
173 infoPtr->uNumTics = nrTics;
176 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
177 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
178 infoPtr->tics[i] = tic;
181 /* converts from physical (mouse) position to logical position
182 (in range of trackbar) */
185 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place)
187 double range, width, pos, offsetthumb;
189 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
190 if (infoPtr->dwStyle & TBS_VERT) {
191 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
192 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
193 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
195 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
196 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
197 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
199 pos += infoPtr->lRangeMin;
200 if (pos > infoPtr->lRangeMax)
201 pos = infoPtr->lRangeMax;
202 else if (pos < infoPtr->lRangeMin)
203 pos = infoPtr->lRangeMin;
205 TRACE("%.2f\n", pos);
206 return (LONG)(pos + 0.5);
210 /* return: 0> prev, 0 none, >0 next */
212 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
216 if (infoPtr->dwStyle & TBS_VERT) {
217 pageRect.top = infoPtr->rcChannel.top;
218 pageRect.bottom = infoPtr->rcChannel.bottom;
219 pageRect.left = infoPtr->rcThumb.left;
220 pageRect.right = infoPtr->rcThumb.right;
222 pageRect.top = infoPtr->rcThumb.top;
223 pageRect.bottom = infoPtr->rcThumb.bottom;
224 pageRect.left = infoPtr->rcChannel.left;
225 pageRect.right = infoPtr->rcChannel.right;
229 if (PtInRect(&pageRect, clickPoint))
231 int clickPlace = (infoPtr->dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
233 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace);
235 return clickPos - infoPtr->lPos;
242 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
244 if (infoPtr->lPos == infoPtr->lRangeMax) return;
246 infoPtr->lPos += infoPtr->lPageSize;
247 if (infoPtr->lPos > infoPtr->lRangeMax)
248 infoPtr->lPos = infoPtr->lRangeMax;
249 notify_with_scroll (infoPtr, TB_PAGEDOWN);
254 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
256 if (infoPtr->lPos == infoPtr->lRangeMin) return;
258 infoPtr->lPos -= infoPtr->lPageSize;
259 if (infoPtr->lPos < infoPtr->lRangeMin)
260 infoPtr->lPos = infoPtr->lRangeMin;
261 notify_with_scroll (infoPtr, TB_PAGEUP);
264 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
266 if (infoPtr->lPos == infoPtr->lRangeMin) return;
267 infoPtr->lPos -= infoPtr->lLineSize;
268 if (infoPtr->lPos < infoPtr->lRangeMin)
269 infoPtr->lPos = infoPtr->lRangeMin;
270 notify_with_scroll (infoPtr, TB_LINEUP);
273 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
275 if (infoPtr->lPos == infoPtr->lRangeMax) return;
276 infoPtr->lPos += infoPtr->lLineSize;
277 if (infoPtr->lPos > infoPtr->lRangeMax)
278 infoPtr->lPos = infoPtr->lRangeMax;
279 notify_with_scroll (infoPtr, TB_LINEDOWN);
283 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
285 INT cyChannel, offsetthumb, offsetedge;
286 RECT lpRect, *channel = & infoPtr->rcChannel;
288 GetClientRect (infoPtr->hwndSelf, &lpRect);
290 offsetthumb = infoPtr->uThumbLen / 4;
291 offsetedge = offsetthumb + 3;
292 cyChannel = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
293 if (infoPtr->dwStyle & TBS_VERT) {
294 channel->top = lpRect.top + offsetedge;
295 channel->bottom = lpRect.bottom - offsetedge;
296 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
297 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
299 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
300 if (infoPtr->dwStyle & TBS_BOTH) {
301 if (infoPtr->dwStyle & TBS_NOTICKS)
306 else if (infoPtr->dwStyle & TBS_TOP) {
307 if (infoPtr->dwStyle & TBS_NOTICKS)
312 channel->right = channel->left + cyChannel;
314 channel->left = lpRect.left + offsetedge;
315 channel->right = lpRect.right - offsetedge;
316 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
317 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
319 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
320 if (infoPtr->dwStyle & TBS_BOTH) {
321 if (infoPtr->dwStyle & TBS_NOTICKS)
326 else if (infoPtr->dwStyle & TBS_TOP) {
327 if (infoPtr->dwStyle & TBS_NOTICKS)
332 channel->bottom = channel->top + cyChannel;
337 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
339 int range, width, height, thumbwidth;
342 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
343 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
345 if (!range) range = 1;
347 GetClientRect(infoPtr->hwndSelf, &lpRect);
348 if (infoPtr->dwStyle & TBS_VERT)
350 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
352 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_LEFT)) && !(infoPtr->dwStyle & TBS_NOTICKS))
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 ((infoPtr->dwStyle & (TBS_BOTH | TBS_TOP)) && !(infoPtr->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 (infoPtr->dwStyle & TBS_VERT) {
423 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
424 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
425 selection->top = infoPtr->rcChannel.top + offsetthumb +
426 (height*infoPtr->lSelMin)/range;
427 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
428 (height*infoPtr->lSelMax)/range;
429 selection->left = infoPtr->rcChannel.left + 3;
430 selection->right = infoPtr->rcChannel.right - 3;
432 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
433 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
434 selection->left = infoPtr->rcChannel.left + offsetthumb +
435 (width*infoPtr->lSelMin)/range;
436 selection->right = infoPtr->rcChannel.left + offsetthumb +
437 (width*infoPtr->lSelMax)/range;
438 selection->top = infoPtr->rcChannel.top + 3;
439 selection->bottom = infoPtr->rcChannel.bottom - 3;
443 TRACE("selection[%s]\n", wine_dbgstr_rect(selection));
447 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
449 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
450 LONG prevPos = infoPtr->lPos;
452 TRACE("x=%d, y=%d, dir=%d\n", clickPoint.x, clickPoint.y, dir);
454 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
455 TRACKBAR_PageDown(infoPtr);
456 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
457 TRACKBAR_PageUp(infoPtr);
460 TRACKBAR_UpdateThumb (infoPtr);
461 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
466 /* Trackbar drawing code. I like my spaghetti done milanese. */
469 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc)
471 RECT rcChannel = infoPtr->rcChannel;
472 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
476 DrawThemeBackground (theme, hdc,
477 (infoPtr->dwStyle & TBS_VERT) ?
478 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
482 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
483 if (infoPtr->dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
484 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
485 if (TRACKBAR_HasSelection(infoPtr))
486 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
492 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
494 int x, y, ox, oy, range, side, indent = 0, len = 3;
498 if (flags & TBS_VERT) {
499 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
500 rcTics.left = infoPtr->rcThumb.left - 2;
501 rcTics.right = infoPtr->rcThumb.right + 2;
502 rcTics.top = infoPtr->rcChannel.top + offsetthumb + 1;
503 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb;
505 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
506 rcTics.left = infoPtr->rcChannel.left + offsetthumb + 1;
507 rcTics.right = infoPtr->rcChannel.right - offsetthumb;
508 rcTics.top = infoPtr->rcThumb.top - 2;
509 rcTics.bottom = infoPtr->rcThumb.bottom + 2;
512 if (flags & (TBS_TOP | TBS_LEFT)) {
522 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
524 range = 1; /* to avoid division by zero */
526 if (flags & TIC_SELECTIONMARK) {
527 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
528 } else if (flags & TIC_EDGE) {
532 if (flags & TBS_VERT) {
533 int height = rcTics.bottom - rcTics.top;
534 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
536 int width = rcTics.right - rcTics.left;
537 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
542 MoveToEx(hdc, x, y, 0);
543 if (flags & TBS_VERT) x += len * side;
544 else y += len * side;
547 if (flags & TIC_SELECTIONMARK) {
548 if (flags & TBS_VERT) {
553 MoveToEx(hdc, x, y, 0);
554 if (flags & TBS_VERT) {
567 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
569 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
570 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
572 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
573 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
577 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc)
580 int ticFlags = infoPtr->dwStyle & 0x0f;
581 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
582 HPEN hOldPen, hTicPen;
583 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
587 int part = (infoPtr->dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
588 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
590 /* create the pen to draw the tics with */
591 hTicPen = CreatePenIndirect(&ticPen);
592 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
594 /* actually draw the tics */
595 for (i=0; i<infoPtr->uNumTics; i++)
596 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
599 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
601 if ((infoPtr->dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
602 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
603 ticFlags | TIC_SELECTIONMARKMIN);
604 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
605 ticFlags | TIC_SELECTIONMARKMAX);
608 /* clean up the pen, if we created one */
610 SelectObject(hdc, hOldPen);
611 DeleteObject(hTicPen);
616 TRACKBAR_DrawThumb (const TRACKBAR_INFO *infoPtr, HDC hdc)
620 RECT thumb = infoPtr->rcThumb;
626 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
632 if (infoPtr->dwStyle & TBS_BOTH)
633 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
634 else if (infoPtr->dwStyle & TBS_LEFT)
635 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
637 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
639 if (infoPtr->dwStyle & WS_DISABLED)
640 stateId = TUS_DISABLED;
641 else if (infoPtr->flags & TB_DRAG_MODE)
642 stateId = TUS_PRESSED;
643 else if (infoPtr->flags & TB_THUMB_HOT)
646 stateId = TUS_NORMAL;
648 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
653 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
654 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
655 SetPolyFillMode (hdc, WINDING);
657 if (infoPtr->dwStyle & TBS_BOTH)
659 points[0].x=thumb.right;
660 points[0].y=thumb.top;
661 points[1].x=thumb.right;
662 points[1].y=thumb.bottom;
663 points[2].x=thumb.left;
664 points[2].y=thumb.bottom;
665 points[3].x=thumb.left;
666 points[3].y=thumb.top;
667 points[4].x=points[0].x;
668 points[4].y=points[0].y;
674 if (infoPtr->dwStyle & TBS_VERT)
676 PointDepth = (thumb.bottom - thumb.top) / 2;
677 if (infoPtr->dwStyle & TBS_LEFT)
679 points[0].x=thumb.right;
680 points[0].y=thumb.top;
681 points[1].x=thumb.right;
682 points[1].y=thumb.bottom;
683 points[2].x=thumb.left + PointDepth;
684 points[2].y=thumb.bottom;
685 points[3].x=thumb.left;
686 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
687 points[4].x=thumb.left + PointDepth;
688 points[4].y=thumb.top;
689 points[5].x=points[0].x;
690 points[5].y=points[0].y;
695 points[0].x=thumb.right;
696 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
697 points[1].x=thumb.right - PointDepth;
698 points[1].y=thumb.bottom;
699 points[2].x=thumb.left;
700 points[2].y=thumb.bottom;
701 points[3].x=thumb.left;
702 points[3].y=thumb.top;
703 points[4].x=thumb.right - PointDepth;
704 points[4].y=thumb.top;
705 points[5].x=points[0].x;
706 points[5].y=points[0].y;
711 PointDepth = (thumb.right - thumb.left) / 2;
712 if (infoPtr->dwStyle & TBS_TOP)
714 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
715 points[0].y=thumb.top;
716 points[1].x=thumb.right;
717 points[1].y=thumb.top + PointDepth;
718 points[2].x=thumb.right;
719 points[2].y=thumb.bottom;
720 points[3].x=thumb.left;
721 points[3].y=thumb.bottom;
722 points[4].x=thumb.left;
723 points[4].y=thumb.top + PointDepth;
724 points[5].x=points[0].x;
725 points[5].y=points[0].y;
730 points[0].x=thumb.right;
731 points[0].y=thumb.top;
732 points[1].x=thumb.right;
733 points[1].y=thumb.bottom - PointDepth;
734 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
735 points[2].y=thumb.bottom;
736 points[3].x=thumb.left;
737 points[3].y=thumb.bottom - PointDepth;
738 points[4].x=thumb.left;
739 points[4].y=thumb.top;
740 points[5].x=points[0].x;
741 points[5].y=points[0].y;
747 /* Draw the thumb now */
748 Polygon (hdc, points, PointCount);
749 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
750 Polyline(hdc,points, BlackUntil);
751 SelectObject(hdc, GetStockObject(WHITE_PEN));
752 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
753 SelectObject(hdc, oldpen);
754 SelectObject(hdc, oldbr);
759 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
763 if (!infoPtr->hwndToolTip) return;
765 ZeroMemory(&ti, sizeof(ti));
766 ti.cbSize = sizeof(ti);
767 ti.hwnd = infoPtr->hwndSelf;
769 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
774 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
777 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
783 if (!infoPtr->hwndToolTip) return;
785 ZeroMemory(&ti, sizeof(ti));
786 ti.cbSize = sizeof(ti);
787 ti.hwnd = infoPtr->hwndSelf;
788 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
790 wsprintfW (buf, fmt, infoPtr->lPos);
792 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
794 GetClientRect (infoPtr->hwndSelf, &rcClient);
795 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
796 if (infoPtr->dwStyle & TBS_VERT) {
797 if (infoPtr->fLocation == TBTS_LEFT)
798 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
800 pt.x = rcClient.right + TOOLTIP_OFFSET;
801 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
803 if (infoPtr->fLocation == TBTS_TOP)
804 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
806 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
807 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
809 ClientToScreen(infoPtr->hwndSelf, &pt);
811 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
812 0, MAKELPARAM(pt.x, pt.y));
817 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
821 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
825 if (infoPtr->flags & TB_THUMBCHANGED) {
826 TRACKBAR_UpdateThumb (infoPtr);
827 if (infoPtr->flags & TB_THUMBSIZECHANGED)
828 TRACKBAR_CalcChannel (infoPtr);
830 if (infoPtr->flags & TB_SELECTIONCHANGED)
831 TRACKBAR_CalcSelection (infoPtr);
833 if (infoPtr->flags & TB_DRAG_MODE)
834 TRACKBAR_UpdateToolTip (infoPtr);
836 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
838 GetClientRect (infoPtr->hwndSelf, &rcClient);
840 /* try to render offscreen, if we fail, carrry onscreen */
841 hdc = CreateCompatibleDC(hdcDst);
843 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
845 hOldBmp = SelectObject(hdc, hOffScreenBmp);
854 ZeroMemory(&nmcd, sizeof(nmcd));
855 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
856 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
857 nmcd.hdr.code = NM_CUSTOMDRAW;
860 /* start the paint cycle */
862 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
863 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
865 /* Erase background */
866 if (gcdrf == CDRF_DODEFAULT ||
867 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
868 if (GetWindowTheme (infoPtr->hwndSelf)) {
869 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
872 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
873 if (gcdrf != CDRF_DODEFAULT)
874 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
878 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
879 nmcd.dwItemSpec = TBCD_CHANNEL;
880 nmcd.uItemState = CDIS_DEFAULT;
881 nmcd.rc = infoPtr->rcChannel;
882 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
883 } else icdrf = CDRF_DODEFAULT;
884 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
885 TRACKBAR_DrawChannel (infoPtr, hdc);
886 if (icdrf & CDRF_NOTIFYPOSTPAINT)
887 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
892 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
893 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
894 nmcd.dwItemSpec = TBCD_TICS;
895 nmcd.uItemState = CDIS_DEFAULT;
897 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
898 } else icdrf = CDRF_DODEFAULT;
899 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
900 TRACKBAR_DrawTics (infoPtr, hdc);
901 if (icdrf & CDRF_NOTIFYPOSTPAINT)
902 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
907 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
908 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
909 nmcd.dwItemSpec = TBCD_THUMB;
910 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
911 nmcd.rc = infoPtr->rcThumb;
912 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
913 } else icdrf = CDRF_DODEFAULT;
914 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
915 TRACKBAR_DrawThumb(infoPtr, hdc);
916 if (icdrf & CDRF_NOTIFYPOSTPAINT)
917 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
921 /* draw focus rectangle */
922 if (infoPtr->bFocussed) {
923 DrawFocusRect(hdc, &rcClient);
926 /* finish up the painting */
927 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
928 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
931 /* cleanup, if we rendered offscreen */
933 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
934 SelectObject(hdc, hOldBmp);
935 DeleteObject(hOffScreenBmp);
942 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
944 HWND hwndParent = GetParent (infoPtr->hwndSelf);
945 RECT rcSelf, rcBuddy;
948 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
949 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
951 /* align buddy left or above */
952 if (infoPtr->hwndBuddyLA) {
953 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
954 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
956 if (infoPtr->dwStyle & TBS_VERT) {
957 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
958 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
959 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
962 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
963 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
964 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
967 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
968 SWP_NOZORDER | SWP_NOSIZE);
972 /* align buddy right or below */
973 if (infoPtr->hwndBuddyRB) {
974 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
975 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
977 if (infoPtr->dwStyle & TBS_VERT) {
978 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
979 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
984 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
985 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
987 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
988 SWP_NOZORDER | SWP_NOSIZE);
994 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
996 infoPtr->lSelMin = 0;
997 infoPtr->lSelMax = 0;
998 infoPtr->flags |= TB_SELECTIONCHANGED;
1000 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1007 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1009 if (infoPtr->tics) {
1010 Free (infoPtr->tics);
1011 infoPtr->tics = NULL;
1012 infoPtr->uNumTics = 0;
1015 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1021 static inline LRESULT
1022 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1024 if (lprc == NULL) return 0;
1026 lprc->left = infoPtr->rcChannel.left;
1027 lprc->right = infoPtr->rcChannel.right;
1028 lprc->bottom = infoPtr->rcChannel.bottom;
1029 lprc->top = infoPtr->rcChannel.top;
1036 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1038 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1040 return infoPtr->uNumTics + 2;
1044 static int comp_tics (const void *ap, const void *bp)
1046 const DWORD a = *(const DWORD *)ap;
1047 const DWORD b = *(const DWORD *)bp;
1049 TRACE("(a=%d, b=%d)\n", a, b);
1050 if (a < b) return -1;
1051 if (a > b) return 1;
1057 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1059 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1062 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1063 return infoPtr->tics[iTic];
1068 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1070 LONG range, width, pos, tic;
1073 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1076 tic = TRACKBAR_GetTic (infoPtr, iTic);
1077 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1078 if (range <= 0) range = 1;
1079 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1080 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1081 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1088 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1093 /* buddy is left or above */
1094 hwndTemp = infoPtr->hwndBuddyLA;
1095 infoPtr->hwndBuddyLA = hwndBuddy;
1098 /* buddy is right or below */
1099 hwndTemp = infoPtr->hwndBuddyRB;
1100 infoPtr->hwndBuddyRB = hwndBuddy;
1103 TRACKBAR_AlignBuddies (infoPtr);
1110 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1112 LONG lTemp = infoPtr->lLineSize;
1114 infoPtr->lLineSize = lLineSize;
1121 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1123 LONG lTemp = infoPtr->lPageSize;
1125 if (lPageSize != -1)
1126 infoPtr->lPageSize = lPageSize;
1128 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1134 static inline LRESULT
1135 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1137 LONG oldPos = infoPtr->lPos;
1138 infoPtr->lPos = lPosition;
1140 if (infoPtr->lPos < infoPtr->lRangeMin)
1141 infoPtr->lPos = infoPtr->lRangeMin;
1143 if (infoPtr->lPos > infoPtr->lRangeMax)
1144 infoPtr->lPos = infoPtr->lRangeMax;
1145 infoPtr->flags |= TB_THUMBPOSCHANGED;
1147 if (fPosition && oldPos != lPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1153 static inline LRESULT
1154 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
1156 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1157 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1159 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1160 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1162 if (infoPtr->lPos < infoPtr->lRangeMin) {
1163 infoPtr->lPos = infoPtr->lRangeMin;
1164 infoPtr->flags |= TB_THUMBPOSCHANGED;
1167 if (infoPtr->lPos > infoPtr->lRangeMax) {
1168 infoPtr->lPos = infoPtr->lRangeMax;
1169 infoPtr->flags |= TB_THUMBPOSCHANGED;
1172 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1173 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1175 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1176 TRACKBAR_RecalculateTics (infoPtr);
1178 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1184 static inline LRESULT
1185 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1187 BOOL changed = infoPtr->lRangeMax != lMax;
1189 infoPtr->lRangeMax = lMax;
1190 if (infoPtr->lPos > infoPtr->lRangeMax) {
1191 infoPtr->lPos = infoPtr->lRangeMax;
1192 infoPtr->flags |= TB_THUMBPOSCHANGED;
1195 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1196 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1198 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1199 TRACKBAR_RecalculateTics (infoPtr);
1201 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1207 static inline LRESULT
1208 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1210 BOOL changed = infoPtr->lRangeMin != lMin;
1212 infoPtr->lRangeMin = lMin;
1213 if (infoPtr->lPos < infoPtr->lRangeMin) {
1214 infoPtr->lPos = infoPtr->lRangeMin;
1215 infoPtr->flags |= TB_THUMBPOSCHANGED;
1218 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1219 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1221 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1222 TRACKBAR_RecalculateTics (infoPtr);
1224 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1230 static inline LRESULT
1231 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1233 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1234 infoPtr->lSelMin = 0;
1235 infoPtr->lSelMax = 0;
1239 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1240 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1241 infoPtr->flags |= TB_SELECTIONCHANGED;
1243 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1244 infoPtr->lSelMin = infoPtr->lRangeMin;
1245 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1246 infoPtr->lSelMax = infoPtr->lRangeMax;
1248 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1254 static inline LRESULT
1255 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1257 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1258 infoPtr->lSelMax = 0;
1262 infoPtr->lSelMax = lEnd;
1263 infoPtr->flags |= TB_SELECTIONCHANGED;
1265 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1266 infoPtr->lSelMax = infoPtr->lRangeMax;
1268 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1274 static inline LRESULT
1275 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1277 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1278 infoPtr->lSelMin = 0;
1282 infoPtr->lSelMin = lStart;
1283 infoPtr->flags |=TB_SELECTIONCHANGED;
1285 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1286 infoPtr->lSelMin = infoPtr->lRangeMin;
1288 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1294 static inline LRESULT
1295 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1297 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1298 infoPtr->uThumbLen = iLength;
1299 infoPtr->flags |= TB_THUMBSIZECHANGED;
1300 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1307 static inline LRESULT
1308 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1310 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1313 TRACE("lPos=%d\n", lPos);
1315 infoPtr->uNumTics++;
1316 infoPtr->tics=ReAlloc( infoPtr->tics,
1317 (infoPtr->uNumTics)*sizeof (DWORD));
1318 if (!infoPtr->tics) {
1319 infoPtr->uNumTics = 0;
1320 notify(infoPtr, NM_OUTOFMEMORY);
1323 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1325 TRACKBAR_InvalidateAll(infoPtr);
1331 static inline LRESULT
1332 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1334 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1335 infoPtr->uTicFreq = wFreq;
1336 TRACKBAR_RecalculateTics (infoPtr);
1337 TRACKBAR_InvalidateAll(infoPtr);
1345 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1347 INT fTemp = infoPtr->fLocation;
1349 infoPtr->fLocation = fLocation;
1355 static inline LRESULT
1356 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1358 infoPtr->hwndToolTip = hwndTT;
1365 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1367 BOOL bTemp = infoPtr->bUnicode;
1369 infoPtr->bUnicode = fUnicode;
1376 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1379 int clientWidth, clientMetric;
1381 /* initial thumb length */
1382 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1383 GetClientRect(infoPtr->hwndSelf,&rect);
1384 if (infoPtr->dwStyle & TBS_VERT) {
1385 clientWidth = rect.right - rect.left;
1387 clientWidth = rect.bottom - rect.top;
1389 if (clientWidth >= clientMetric)
1390 infoPtr->uThumbLen = clientMetric;
1392 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1394 TRACKBAR_CalcChannel (infoPtr);
1395 TRACKBAR_UpdateThumb (infoPtr);
1396 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1403 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1405 TRACKBAR_INFO *infoPtr;
1407 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1408 if (!infoPtr) return -1;
1409 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1411 /* set default values */
1412 infoPtr->hwndSelf = hwnd;
1413 infoPtr->dwStyle = lpcs->style;
1414 infoPtr->lRangeMin = 0;
1415 infoPtr->lRangeMax = 100;
1416 infoPtr->lLineSize = 1;
1417 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1418 infoPtr->lSelMin = 0;
1419 infoPtr->lSelMax = 0;
1421 infoPtr->fLocation = TBTS_TOP;
1422 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1423 infoPtr->uTicFreq = 1;
1424 infoPtr->tics = NULL;
1425 infoPtr->hwndNotify= lpcs->hwndParent;
1427 TRACKBAR_InitializeThumb (infoPtr);
1429 /* Create tooltip control */
1430 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1432 infoPtr->hwndToolTip =
1433 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1434 CW_USEDEFAULT, CW_USEDEFAULT,
1435 CW_USEDEFAULT, CW_USEDEFAULT,
1438 if (infoPtr->hwndToolTip) {
1440 ZeroMemory (&ti, sizeof(ti));
1441 ti.cbSize = sizeof(ti);
1442 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1445 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1449 OpenThemeData (hwnd, themeClass);
1456 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1458 /* delete tooltip control */
1459 if (infoPtr->hwndToolTip)
1460 DestroyWindow (infoPtr->hwndToolTip);
1462 Free (infoPtr->tics);
1463 infoPtr->tics = NULL;
1465 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1466 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1474 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1477 infoPtr->bFocussed = FALSE;
1478 TRACKBAR_InvalidateAll(infoPtr);
1484 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1491 SetFocus(infoPtr->hwndSelf);
1493 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1494 infoPtr->flags |= TB_DRAG_MODE;
1495 SetCapture (infoPtr->hwndSelf);
1496 TRACKBAR_UpdateToolTip (infoPtr);
1497 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1498 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1500 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1501 if (dir == 0) return 0;
1502 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1503 TRACKBAR_AutoPage (infoPtr, clickPoint);
1504 SetCapture (infoPtr->hwndSelf);
1505 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1513 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1515 if (infoPtr->flags & TB_DRAG_MODE) {
1516 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1517 notify_with_scroll (infoPtr, TB_ENDTRACK);
1518 infoPtr->flags &= ~TB_DRAG_MODE;
1520 notify(infoPtr, NM_RELEASEDCAPTURE);
1521 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1522 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1524 if (infoPtr->flags & TB_AUTO_PAGE) {
1525 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1526 infoPtr->flags &= ~TB_AUTO_PAGE;
1527 notify_with_scroll (infoPtr, TB_ENDTRACK);
1529 notify(infoPtr, NM_RELEASEDCAPTURE);
1537 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1539 notify_with_scroll (infoPtr, TB_ENDTRACK);
1545 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1548 TRACKBAR_Refresh(infoPtr, hdc);
1551 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1552 TRACKBAR_Refresh (infoPtr, hdc);
1553 EndPaint (infoPtr->hwndSelf, &ps);
1561 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1564 infoPtr->bFocussed = TRUE;
1565 TRACKBAR_InvalidateAll(infoPtr);
1572 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1574 TRACKBAR_CalcChannel (infoPtr);
1575 TRACKBAR_UpdateThumb (infoPtr);
1576 TRACKBAR_AlignBuddies (infoPtr);
1582 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1583 const STYLESTRUCT *lpss)
1585 if (wStyleType != GWL_STYLE) return 0;
1587 infoPtr->dwStyle = lpss->styleNew;
1593 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1595 if (infoPtr->flags & TB_AUTO_PAGE) {
1597 if (GetCursorPos(&pt))
1598 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1599 TRACKBAR_AutoPage(infoPtr, pt);
1605 /* update theme after a WM_THEMECHANGED message */
1606 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1608 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1609 CloseThemeData (theme);
1610 OpenThemeData (infoPtr->hwndSelf, themeClass);
1616 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1618 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1619 LONG dragPos, oldPos = infoPtr->lPos;
1621 TRACE("(x=%d. y=%d)\n", x, y);
1623 if (infoPtr->flags & TB_AUTO_PAGE) {
1627 TRACKBAR_AutoPage (infoPtr, pt);
1631 if (!(infoPtr->flags & TB_DRAG_MODE))
1633 if (GetWindowTheme (infoPtr->hwndSelf))
1635 DWORD oldFlags = infoPtr->flags;
1639 if (PtInRect (&infoPtr->rcThumb, pt))
1641 TRACKMOUSEEVENT tme;
1642 tme.cbSize = sizeof( tme );
1643 tme.dwFlags = TME_LEAVE;
1644 tme.hwndTrack = infoPtr->hwndSelf;
1645 TrackMouseEvent( &tme );
1646 infoPtr->flags |= TB_THUMB_HOT;
1650 TRACKMOUSEEVENT tme;
1651 tme.cbSize = sizeof( tme );
1652 tme.dwFlags = TME_CANCEL;
1653 tme.hwndTrack = infoPtr->hwndSelf;
1654 TrackMouseEvent( &tme );
1655 infoPtr->flags &= ~TB_THUMB_HOT;
1657 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1662 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1664 if (dragPos == oldPos) return TRUE;
1666 infoPtr->lPos = dragPos;
1667 TRACKBAR_UpdateThumb (infoPtr);
1669 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1671 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1672 UpdateWindow (infoPtr->hwndSelf);
1678 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1680 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1681 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1682 LONG pos = infoPtr->lPos;
1684 TRACE("%x\n", nVirtKey);
1688 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1689 else TRACKBAR_LineUp(infoPtr);
1692 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1693 else TRACKBAR_LineUp(infoPtr);
1696 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1697 else TRACKBAR_LineDown(infoPtr);
1700 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1701 else TRACKBAR_LineDown(infoPtr);
1704 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1705 else TRACKBAR_PageDown(infoPtr);
1708 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1709 else TRACKBAR_PageUp(infoPtr);
1712 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1713 infoPtr->lPos = infoPtr->lRangeMin;
1714 notify_with_scroll (infoPtr, TB_TOP);
1717 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1718 infoPtr->lPos = infoPtr->lRangeMax;
1719 notify_with_scroll (infoPtr, TB_BOTTOM);
1723 if (pos != infoPtr->lPos) {
1724 infoPtr->flags |=TB_THUMBPOSCHANGED;
1725 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1733 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1744 notify_with_scroll (infoPtr, TB_ENDTRACK);
1750 static LRESULT WINAPI
1751 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1753 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1755 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1757 if (!infoPtr && (uMsg != WM_CREATE))
1758 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1763 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1766 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1769 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1771 case TBM_GETCHANNELRECT:
1772 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1774 case TBM_GETLINESIZE:
1775 return infoPtr->lLineSize;
1777 case TBM_GETNUMTICS:
1778 return TRACKBAR_GetNumTics (infoPtr);
1780 case TBM_GETPAGESIZE:
1781 return infoPtr->lPageSize;
1784 return infoPtr->lPos;
1787 return (LRESULT)infoPtr->tics;
1789 case TBM_GETRANGEMAX:
1790 return infoPtr->lRangeMax;
1792 case TBM_GETRANGEMIN:
1793 return infoPtr->lRangeMin;
1796 return infoPtr->lSelMax;
1798 case TBM_GETSELSTART:
1799 return infoPtr->lSelMin;
1801 case TBM_GETTHUMBLENGTH:
1802 return infoPtr->uThumbLen;
1804 case TBM_GETTHUMBRECT:
1805 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1808 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1811 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1813 case TBM_GETTOOLTIPS:
1814 return (LRESULT)infoPtr->hwndToolTip;
1816 case TBM_GETUNICODEFORMAT:
1817 return infoPtr->bUnicode;
1820 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1822 case TBM_SETLINESIZE:
1823 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1825 case TBM_SETPAGESIZE:
1826 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1829 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1832 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1834 case TBM_SETRANGEMAX:
1835 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1837 case TBM_SETRANGEMIN:
1838 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1841 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1844 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1846 case TBM_SETSELSTART:
1847 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1849 case TBM_SETTHUMBLENGTH:
1850 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1853 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1855 case TBM_SETTICFREQ:
1856 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1858 case TBM_SETTIPSIDE:
1859 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1861 case TBM_SETTOOLTIPS:
1862 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1864 case TBM_SETUNICODEFORMAT:
1865 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1868 case WM_CAPTURECHANGED:
1869 return TRACKBAR_CaptureChanged (infoPtr);
1872 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1875 return TRACKBAR_Destroy (infoPtr);
1877 /* case WM_ENABLE: */
1883 return DLGC_WANTARROWS;
1886 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
1889 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
1892 return TRACKBAR_KillFocus (infoPtr);
1894 case WM_LBUTTONDOWN:
1895 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1898 return TRACKBAR_LButtonUp (infoPtr);
1901 infoPtr->flags &= ~TB_THUMB_HOT;
1902 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1906 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1908 case WM_PRINTCLIENT:
1910 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1913 return TRACKBAR_SetFocus (infoPtr);
1916 return TRACKBAR_Size (infoPtr);
1918 case WM_STYLECHANGED:
1919 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
1921 case WM_THEMECHANGED:
1922 return theme_changed (infoPtr);
1925 return TRACKBAR_Timer (infoPtr);
1927 case WM_WININICHANGE:
1928 return TRACKBAR_InitializeThumb (infoPtr);
1931 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
1932 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
1933 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1938 void TRACKBAR_Register (void)
1942 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1943 wndClass.style = CS_GLOBALCLASS;
1944 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1945 wndClass.cbClsExtra = 0;
1946 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1947 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1948 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1949 wndClass.lpszClassName = TRACKBAR_CLASSW;
1951 RegisterClassW (&wndClass);
1955 void TRACKBAR_Unregister (void)
1957 UnregisterClassW (TRACKBAR_CLASSW, NULL);