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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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(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)
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(TRACKBAR_INFO *infoPtr, INT code)
133 return notify_hdr(infoPtr, code, &nmh);
137 notify_with_scroll (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 (TRACKBAR_INFO *infoPtr, int place,
185 double range, width, pos, offsetthumb;
187 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
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;
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 */
210 TRACKBAR_GetAutoPageDirection (TRACKBAR_INFO *infoPtr, POINT clickPoint)
212 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
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;
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,
234 return clickPos - infoPtr->lPos;
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);
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 static void inline 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 static void inline 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);
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);
299 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
300 if (dwStyle & TBS_BOTH) {
301 if (dwStyle & TBS_NOTICKS)
306 else if (dwStyle & TBS_TOP) {
307 if (dwStyle & TBS_NOTICKS)
312 channel->right = channel->left + cyChannel;
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);
319 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
320 if (dwStyle & TBS_BOTH) {
321 if (dwStyle & TBS_NOTICKS)
326 else if (dwStyle & TBS_TOP) {
327 if (dwStyle & TBS_NOTICKS)
332 channel->bottom = channel->top + cyChannel;
337 TRACKBAR_CalcThumb (TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
339 int range, width, height, thumbwidth;
340 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
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))
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;
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))
373 thumb->bottom = thumb->top + infoPtr->uThumbLen;
378 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
380 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
384 TRACKBAR_InvalidateAll(TRACKBAR_INFO * infoPtr)
386 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
390 TRACKBAR_InvalidateThumb (TRACKBAR_INFO *infoPtr, LONG thumbPos)
394 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
395 InflateRect(&rcThumb, 1, 1);
396 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
400 TRACKBAR_InvalidateThumbMove (TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
402 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
403 if (newPos != oldPos)
404 TRACKBAR_InvalidateThumb (infoPtr, newPos);
408 TRACKBAR_HasSelection (TRACKBAR_INFO *infoPtr)
410 return infoPtr->lSelMin != infoPtr->lSelMax;
414 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
416 RECT *selection = &infoPtr->rcSelection;
417 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
418 int offsetthumb, height, width;
421 SetRectEmpty (selection);
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;
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);
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);
462 infoPtr->flags |= TB_THUMBPOSCHANGED;
463 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
468 /* Trackbar drawing code. I like my spaghetti done milanese. */
471 TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
473 RECT rcChannel = infoPtr->rcChannel;
474 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
478 DrawThemeBackground (theme, hdc,
479 (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) ?
480 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
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));
494 TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
496 int x, y, ox, oy, range, side, indent = 0, len = 3;
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;
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)) {
524 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
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) {
534 if (flags & TBS_VERT) {
535 int height = rcTics.bottom - rcTics.top;
536 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
538 int width = rcTics.right - rcTics.left;
539 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
544 MoveToEx(hdc, x, y, 0);
545 if (flags & TBS_VERT) x += len * side;
546 else y += len * side;
549 if (flags & TIC_SELECTIONMARK) {
550 if (flags & TBS_VERT) {
555 MoveToEx(hdc, x, y, 0);
556 if (flags & TBS_VERT) {
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);
579 TRACKBAR_DrawTics (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
582 int ticFlags = dwStyle & 0x0f;
583 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
584 HPEN hOldPen, hTicPen;
586 /* create the pen to draw the tics with */
587 hTicPen = CreatePenIndirect(&ticPen);
588 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
590 /* actually draw the tics */
591 for (i=0; i<infoPtr->uNumTics; i++)
592 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
594 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
595 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
597 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
599 ticFlags | TIC_SELECTIONMARKMIN);
600 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
601 ticFlags | TIC_SELECTIONMARKMAX);
604 /* clean up the pen, if we created one */
606 SelectObject(hdc, hOldPen);
607 DeleteObject(hTicPen);
612 TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
616 RECT thumb = infoPtr->rcThumb;
622 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
628 if (dwStyle & TBS_BOTH)
629 partId = (dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
630 else if (dwStyle & TBS_LEFT)
631 partId = (dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
633 partId = (dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
635 if (dwStyle & WS_DISABLED)
636 stateId = TUS_DISABLED;
637 else if (infoPtr->flags & TB_DRAG_MODE)
638 stateId = TUS_PRESSED;
639 else if (infoPtr->flags & TB_THUMB_HOT)
642 stateId = TUS_NORMAL;
644 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
649 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
650 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
651 SetPolyFillMode (hdc, WINDING);
653 if (dwStyle & TBS_BOTH)
655 points[0].x=thumb.right;
656 points[0].y=thumb.top;
657 points[1].x=thumb.right;
658 points[1].y=thumb.bottom;
659 points[2].x=thumb.left;
660 points[2].y=thumb.bottom;
661 points[3].x=thumb.left;
662 points[3].y=thumb.top;
663 points[4].x=points[0].x;
664 points[4].y=points[0].y;
670 if (dwStyle & TBS_VERT)
672 PointDepth = (thumb.bottom - thumb.top) / 2;
673 if (dwStyle & TBS_LEFT)
675 points[0].x=thumb.right;
676 points[0].y=thumb.top;
677 points[1].x=thumb.right;
678 points[1].y=thumb.bottom;
679 points[2].x=thumb.left + PointDepth;
680 points[2].y=thumb.bottom;
681 points[3].x=thumb.left;
682 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
683 points[4].x=thumb.left + PointDepth;
684 points[4].y=thumb.top;
685 points[5].x=points[0].x;
686 points[5].y=points[0].y;
691 points[0].x=thumb.right;
692 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
693 points[1].x=thumb.right - PointDepth;
694 points[1].y=thumb.bottom;
695 points[2].x=thumb.left;
696 points[2].y=thumb.bottom;
697 points[3].x=thumb.left;
698 points[3].y=thumb.top;
699 points[4].x=thumb.right - PointDepth;
700 points[4].y=thumb.top;
701 points[5].x=points[0].x;
702 points[5].y=points[0].y;
707 PointDepth = (thumb.right - thumb.left) / 2;
708 if (dwStyle & TBS_TOP)
710 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
711 points[0].y=thumb.top;
712 points[1].x=thumb.right;
713 points[1].y=thumb.top + PointDepth;
714 points[2].x=thumb.right;
715 points[2].y=thumb.bottom;
716 points[3].x=thumb.left;
717 points[3].y=thumb.bottom;
718 points[4].x=thumb.left;
719 points[4].y=thumb.top + PointDepth;
720 points[5].x=points[0].x;
721 points[5].y=points[0].y;
726 points[0].x=thumb.right;
727 points[0].y=thumb.top;
728 points[1].x=thumb.right;
729 points[1].y=thumb.bottom - PointDepth;
730 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
731 points[2].y=thumb.bottom;
732 points[3].x=thumb.left;
733 points[3].y=thumb.bottom - PointDepth;
734 points[4].x=thumb.left;
735 points[4].y=thumb.top;
736 points[5].x=points[0].x;
737 points[5].y=points[0].y;
743 /* Draw the thumb now */
744 Polygon (hdc, points, PointCount);
745 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
746 Polyline(hdc,points, BlackUntil);
747 SelectObject(hdc, GetStockObject(WHITE_PEN));
748 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
749 SelectObject(hdc, oldpen);
750 SelectObject(hdc, oldbr);
755 TRACKBAR_ActivateToolTip (TRACKBAR_INFO *infoPtr, BOOL fShow)
759 if (!infoPtr->hwndToolTip) return;
761 ZeroMemory(&ti, sizeof(ti));
762 ti.cbSize = sizeof(ti);
763 ti.hwnd = infoPtr->hwndSelf;
765 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
770 TRACKBAR_UpdateToolTip (TRACKBAR_INFO *infoPtr)
772 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
774 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
780 if (!infoPtr->hwndToolTip) return;
782 ZeroMemory(&ti, sizeof(ti));
783 ti.cbSize = sizeof(ti);
784 ti.hwnd = infoPtr->hwndSelf;
785 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
787 wsprintfW (buf, fmt, infoPtr->lPos);
789 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
791 GetClientRect (infoPtr->hwndSelf, &rcClient);
792 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
793 if (dwStyle & TBS_VERT) {
794 if (infoPtr->fLocation == TBTS_LEFT)
795 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
797 pt.x = rcClient.right + TOOLTIP_OFFSET;
798 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
800 if (infoPtr->fLocation == TBTS_TOP)
801 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
803 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
804 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
806 ClientToScreen(infoPtr->hwndSelf, &pt);
808 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
809 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
814 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
816 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
819 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
823 if (infoPtr->flags & TB_THUMBCHANGED) {
824 TRACKBAR_UpdateThumb (infoPtr);
825 if (infoPtr->flags & TB_THUMBSIZECHANGED)
826 TRACKBAR_CalcChannel (infoPtr);
828 if (infoPtr->flags & TB_SELECTIONCHANGED)
829 TRACKBAR_CalcSelection (infoPtr);
831 if (infoPtr->flags & TB_DRAG_MODE)
832 TRACKBAR_UpdateToolTip (infoPtr);
834 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
836 GetClientRect (infoPtr->hwndSelf, &rcClient);
838 /* try to render offscreen, if we fail, carrry onscreen */
839 hdc = CreateCompatibleDC(hdcDst);
841 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
843 hOldBmp = SelectObject(hdc, hOffScreenBmp);
852 ZeroMemory(&nmcd, sizeof(nmcd));
853 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
854 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
855 nmcd.hdr.code = NM_CUSTOMDRAW;
858 /* start the paint cycle */
860 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
861 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
863 /* Erase backbround */
864 if (gcdrf == CDRF_DODEFAULT ||
865 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
866 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
867 if (gcdrf != CDRF_DODEFAULT)
868 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
872 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
873 nmcd.dwItemSpec = TBCD_CHANNEL;
874 nmcd.uItemState = CDIS_DEFAULT;
875 nmcd.rc = infoPtr->rcChannel;
876 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
877 } else icdrf = CDRF_DODEFAULT;
878 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
879 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
880 if (icdrf & CDRF_NOTIFYPOSTPAINT)
881 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
886 if (!(dwStyle & TBS_NOTICKS)) {
887 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
888 nmcd.dwItemSpec = TBCD_TICS;
889 nmcd.uItemState = CDIS_DEFAULT;
891 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
892 } else icdrf = CDRF_DODEFAULT;
893 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
894 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
895 if (icdrf & CDRF_NOTIFYPOSTPAINT)
896 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
901 if (!(dwStyle & TBS_NOTHUMB)) {
902 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
903 nmcd.dwItemSpec = TBCD_THUMB;
904 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
905 nmcd.rc = infoPtr->rcThumb;
906 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
907 } else icdrf = CDRF_DODEFAULT;
908 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
909 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
910 if (icdrf & CDRF_NOTIFYPOSTPAINT)
911 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
915 /* draw focus rectangle */
916 if (infoPtr->bFocussed) {
917 DrawFocusRect(hdc, &rcClient);
920 /* finish up the painting */
921 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
922 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
925 /* cleanup, if we rendered offscreen */
927 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
928 SelectObject(hdc, hOldBmp);
929 DeleteObject(hOffScreenBmp);
936 TRACKBAR_AlignBuddies (TRACKBAR_INFO *infoPtr)
938 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
939 HWND hwndParent = GetParent (infoPtr->hwndSelf);
940 RECT rcSelf, rcBuddy;
943 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
944 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
946 /* align buddy left or above */
947 if (infoPtr->hwndBuddyLA) {
948 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
949 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
951 if (dwStyle & TBS_VERT) {
952 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
953 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
954 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
957 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
958 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
959 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
962 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
963 SWP_NOZORDER | SWP_NOSIZE);
967 /* align buddy right or below */
968 if (infoPtr->hwndBuddyRB) {
969 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
970 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
972 if (dwStyle & TBS_VERT) {
973 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
974 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
979 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
980 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
982 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
983 SWP_NOZORDER | SWP_NOSIZE);
989 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
991 infoPtr->lSelMin = 0;
992 infoPtr->lSelMax = 0;
993 infoPtr->flags |= TB_SELECTIONCHANGED;
995 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1002 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1004 if (infoPtr->tics) {
1005 Free (infoPtr->tics);
1006 infoPtr->tics = NULL;
1007 infoPtr->uNumTics = 0;
1010 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1016 static LRESULT inline
1017 TRACKBAR_GetChannelRect (TRACKBAR_INFO *infoPtr, LPRECT lprc)
1019 if (lprc == NULL) return 0;
1021 lprc->left = infoPtr->rcChannel.left;
1022 lprc->right = infoPtr->rcChannel.right;
1023 lprc->bottom = infoPtr->rcChannel.bottom;
1024 lprc->top = infoPtr->rcChannel.top;
1031 TRACKBAR_GetNumTics (TRACKBAR_INFO *infoPtr)
1033 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
1036 return infoPtr->uNumTics + 2;
1040 static int comp_tics(const void *ap, const void *bp)
1042 DWORD a = *((DWORD *)ap);
1043 DWORD b = *((DWORD *)bp);
1045 TRACE("(a=%ld, b=%ld)\n", a, b);
1046 if (a < b) return -1;
1047 if (a > b) return 1;
1053 TRACKBAR_GetTic (TRACKBAR_INFO *infoPtr, INT iTic)
1055 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1058 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1059 return infoPtr->tics[iTic];
1064 TRACKBAR_GetTicPos (TRACKBAR_INFO *infoPtr, INT iTic)
1066 LONG range, width, pos, tic;
1069 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1072 tic = TRACKBAR_GetTic (infoPtr, iTic);
1073 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1074 if (range <= 0) range = 1;
1075 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1076 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1077 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1084 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1089 /* buddy is left or above */
1090 hwndTemp = infoPtr->hwndBuddyLA;
1091 infoPtr->hwndBuddyLA = hwndBuddy;
1094 /* buddy is right or below */
1095 hwndTemp = infoPtr->hwndBuddyRB;
1096 infoPtr->hwndBuddyRB = hwndBuddy;
1099 TRACKBAR_AlignBuddies (infoPtr);
1106 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1108 LONG lTemp = infoPtr->lLineSize;
1110 infoPtr->lLineSize = lLineSize;
1117 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1119 LONG lTemp = infoPtr->lPageSize;
1121 infoPtr->lPageSize = lPageSize;
1127 static LRESULT inline
1128 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1130 LONG oldPos = infoPtr->lPos;
1131 infoPtr->lPos = lPosition;
1133 if (infoPtr->lPos < infoPtr->lRangeMin)
1134 infoPtr->lPos = infoPtr->lRangeMin;
1136 if (infoPtr->lPos > infoPtr->lRangeMax)
1137 infoPtr->lPos = infoPtr->lRangeMax;
1138 infoPtr->flags |= TB_THUMBPOSCHANGED;
1140 if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1146 static LRESULT inline
1147 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1149 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1150 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1152 if (infoPtr->lPos < infoPtr->lRangeMin) {
1153 infoPtr->lPos = infoPtr->lRangeMin;
1154 infoPtr->flags |= TB_THUMBPOSCHANGED;
1157 if (infoPtr->lPos > infoPtr->lRangeMax) {
1158 infoPtr->lPos = infoPtr->lRangeMax;
1159 infoPtr->flags |= TB_THUMBPOSCHANGED;
1162 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1163 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1165 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1171 static LRESULT inline
1172 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1174 infoPtr->lRangeMax = lMax;
1175 if (infoPtr->lPos > infoPtr->lRangeMax) {
1176 infoPtr->lPos = infoPtr->lRangeMax;
1177 infoPtr->flags |= TB_THUMBPOSCHANGED;
1180 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1181 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1183 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1189 static LRESULT inline
1190 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1192 infoPtr->lRangeMin = lMin;
1193 if (infoPtr->lPos < infoPtr->lRangeMin) {
1194 infoPtr->lPos = infoPtr->lRangeMin;
1195 infoPtr->flags |= TB_THUMBPOSCHANGED;
1198 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1199 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1201 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1207 static LRESULT inline
1208 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1210 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1213 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1214 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1215 infoPtr->flags |= TB_SELECTIONCHANGED;
1217 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1218 infoPtr->lSelMin = infoPtr->lRangeMin;
1219 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1220 infoPtr->lSelMax = infoPtr->lRangeMax;
1222 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1228 static LRESULT inline
1229 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1231 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1234 infoPtr->lSelMax = lEnd;
1235 infoPtr->flags |= TB_SELECTIONCHANGED;
1237 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1238 infoPtr->lSelMax = infoPtr->lRangeMax;
1240 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1246 static LRESULT inline
1247 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1249 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1252 infoPtr->lSelMin = lStart;
1253 infoPtr->flags |=TB_SELECTIONCHANGED;
1255 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1256 infoPtr->lSelMin = infoPtr->lRangeMin;
1258 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1264 static LRESULT inline
1265 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1267 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) {
1268 infoPtr->uThumbLen = iLength;
1269 infoPtr->flags |= TB_THUMBSIZECHANGED;
1270 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1277 static LRESULT inline
1278 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1280 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1283 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1286 TRACE("lPos=%ld\n", lPos);
1288 infoPtr->uNumTics++;
1289 infoPtr->tics=ReAlloc( infoPtr->tics,
1290 (infoPtr->uNumTics)*sizeof (DWORD));
1291 if (!infoPtr->tics) {
1292 infoPtr->uNumTics = 0;
1293 notify(infoPtr, NM_OUTOFMEMORY);
1296 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1298 TRACKBAR_InvalidateAll(infoPtr);
1304 static LRESULT inline
1305 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1307 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1308 infoPtr->uTicFreq = wFreq;
1309 TRACKBAR_RecalculateTics (infoPtr);
1310 TRACKBAR_InvalidateAll(infoPtr);
1318 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1320 INT fTemp = infoPtr->fLocation;
1322 infoPtr->fLocation = fLocation;
1328 static LRESULT inline
1329 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1331 infoPtr->hwndToolTip = hwndTT;
1338 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1340 BOOL bTemp = infoPtr->bUnicode;
1342 infoPtr->bUnicode = fUnicode;
1349 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1351 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1353 int clientWidth, clientMetric;
1355 /* initial thumb length */
1356 clientMetric = (dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1357 GetClientRect(infoPtr->hwndSelf,&rect);
1358 if (dwStyle & TBS_VERT) {
1359 clientWidth = rect.right - rect.left;
1361 clientWidth = rect.bottom - rect.top;
1363 if (clientWidth >= clientMetric)
1364 infoPtr->uThumbLen = clientMetric;
1366 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1368 TRACKBAR_CalcChannel (infoPtr);
1369 TRACKBAR_UpdateThumb (infoPtr);
1370 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1377 TRACKBAR_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
1379 TRACKBAR_INFO *infoPtr;
1382 infoPtr = (TRACKBAR_INFO *)Alloc (sizeof(TRACKBAR_INFO));
1383 if (!infoPtr) return -1;
1384 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1386 /* set default values */
1387 infoPtr->hwndSelf = hwnd;
1388 infoPtr->lRangeMin = 0;
1389 infoPtr->lRangeMax = 100;
1390 infoPtr->lLineSize = 1;
1391 infoPtr->lPageSize = 20;
1392 infoPtr->lSelMin = 0;
1393 infoPtr->lSelMax = 0;
1395 infoPtr->fLocation = -1;
1396 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1397 infoPtr->uTicFreq = 1;
1398 infoPtr->tics = NULL;
1399 infoPtr->hwndNotify= lpcs->hwndParent;
1401 TRACKBAR_InitializeThumb (infoPtr);
1403 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1405 /* Create tooltip control */
1406 if (dwStyle & TBS_TOOLTIPS) {
1408 infoPtr->hwndToolTip =
1409 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
1410 CW_USEDEFAULT, CW_USEDEFAULT,
1411 CW_USEDEFAULT, CW_USEDEFAULT,
1414 if (infoPtr->hwndToolTip) {
1416 ZeroMemory (&ti, sizeof(ti));
1417 ti.cbSize = sizeof(ti);
1418 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1421 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1425 OpenThemeData (hwnd, themeClass);
1432 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1434 /* delete tooltip control */
1435 if (infoPtr->hwndToolTip)
1436 DestroyWindow (infoPtr->hwndToolTip);
1439 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1440 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1446 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
1449 infoPtr->bFocussed = FALSE;
1450 TRACKBAR_InvalidateAll(infoPtr);
1456 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1463 SetFocus(infoPtr->hwndSelf);
1465 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1466 infoPtr->flags |= TB_DRAG_MODE;
1467 SetCapture (infoPtr->hwndSelf);
1468 TRACKBAR_UpdateToolTip (infoPtr);
1469 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1470 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1472 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1473 if (dir == 0) return 0;
1474 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1475 TRACKBAR_AutoPage (infoPtr, clickPoint);
1476 SetCapture (infoPtr->hwndSelf);
1477 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1485 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1487 if (infoPtr->flags & TB_DRAG_MODE) {
1488 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1489 notify_with_scroll (infoPtr, TB_ENDTRACK);
1490 infoPtr->flags &= ~TB_DRAG_MODE;
1492 notify(infoPtr, NM_RELEASEDCAPTURE);
1493 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1494 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1496 if (infoPtr->flags & TB_AUTO_PAGE) {
1497 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1498 infoPtr->flags &= ~TB_AUTO_PAGE;
1499 notify_with_scroll (infoPtr, TB_ENDTRACK);
1501 notify(infoPtr, NM_RELEASEDCAPTURE);
1509 TRACKBAR_CaptureChanged (TRACKBAR_INFO *infoPtr)
1511 notify_with_scroll (infoPtr, TB_ENDTRACK);
1517 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1520 TRACKBAR_Refresh(infoPtr, hdc);
1523 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1524 TRACKBAR_Refresh (infoPtr, hdc);
1525 EndPaint (infoPtr->hwndSelf, &ps);
1533 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
1536 infoPtr->bFocussed = TRUE;
1537 TRACKBAR_InvalidateAll(infoPtr);
1544 TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
1546 TRACKBAR_InitializeThumb (infoPtr);
1547 TRACKBAR_AlignBuddies (infoPtr);
1554 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, TIMERPROC *tmrpc)
1556 if (infoPtr->flags & TB_AUTO_PAGE) {
1558 if (GetCursorPos(&pt))
1559 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1560 TRACKBAR_AutoPage(infoPtr, pt);
1566 /* update theme after a WM_THEMECHANGED message */
1567 static LRESULT theme_changed (TRACKBAR_INFO* infoPtr)
1569 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1570 CloseThemeData (theme);
1571 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
1577 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1579 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1580 INT clickPlace = (dwStyle & TBS_VERT) ? y : x;
1581 LONG dragPos, oldPos = infoPtr->lPos;
1583 TRACE("(x=%d. y=%d)\n", x, y);
1585 if (infoPtr->flags & TB_AUTO_PAGE) {
1589 TRACKBAR_AutoPage (infoPtr, pt);
1593 if (!(infoPtr->flags & TB_DRAG_MODE))
1595 if (GetWindowTheme (infoPtr->hwndSelf))
1597 DWORD oldFlags = infoPtr->flags;
1601 if (PtInRect (&infoPtr->rcThumb, pt))
1603 TRACKMOUSEEVENT tme;
1604 tme.cbSize = sizeof( tme );
1605 tme.dwFlags = TME_LEAVE;
1606 tme.hwndTrack = infoPtr->hwndSelf;
1607 TrackMouseEvent( &tme );
1608 infoPtr->flags |= TB_THUMB_HOT;
1612 TRACKMOUSEEVENT tme;
1613 tme.cbSize = sizeof( tme );
1614 tme.dwFlags = TME_CANCEL;
1615 tme.hwndTrack = infoPtr->hwndSelf;
1616 TrackMouseEvent( &tme );
1617 infoPtr->flags &= ~TB_THUMB_HOT;
1619 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1624 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1625 dwStyle & TBS_VERT);
1626 if (dragPos == oldPos) return TRUE;
1628 infoPtr->lPos = dragPos;
1630 infoPtr->flags |= TB_THUMBPOSCHANGED;
1631 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1634 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1635 UpdateWindow (infoPtr->hwndSelf);
1641 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1643 DWORD style = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1644 BOOL downIsLeft = style & TBS_DOWNISLEFT;
1645 BOOL vert = style & TBS_VERT;
1646 LONG pos = infoPtr->lPos;
1648 TRACE("%x\n", nVirtKey);
1652 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1653 else TRACKBAR_LineUp(infoPtr);
1656 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1657 else TRACKBAR_LineUp(infoPtr);
1660 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1661 else TRACKBAR_LineDown(infoPtr);
1664 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1665 else TRACKBAR_LineDown(infoPtr);
1668 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1669 else TRACKBAR_PageDown(infoPtr);
1672 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1673 else TRACKBAR_PageUp(infoPtr);
1676 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1677 infoPtr->lPos = infoPtr->lRangeMin;
1678 notify_with_scroll (infoPtr, TB_TOP);
1681 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1682 infoPtr->lPos = infoPtr->lRangeMax;
1683 notify_with_scroll (infoPtr, TB_BOTTOM);
1687 if (pos != infoPtr->lPos) {
1688 infoPtr->flags |=TB_THUMBPOSCHANGED;
1689 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1697 TRACKBAR_KeyUp (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1708 notify_with_scroll (infoPtr, TB_ENDTRACK);
1714 static LRESULT WINAPI
1715 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1717 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1719 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1721 if (!infoPtr && (uMsg != WM_CREATE))
1722 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1727 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1730 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1733 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1735 case TBM_GETCHANNELRECT:
1736 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1738 case TBM_GETLINESIZE:
1739 return infoPtr->lLineSize;
1741 case TBM_GETNUMTICS:
1742 return TRACKBAR_GetNumTics (infoPtr);
1744 case TBM_GETPAGESIZE:
1745 return infoPtr->lPageSize;
1748 return infoPtr->lPos;
1751 return (LRESULT)infoPtr->tics;
1753 case TBM_GETRANGEMAX:
1754 return infoPtr->lRangeMax;
1756 case TBM_GETRANGEMIN:
1757 return infoPtr->lRangeMin;
1760 return infoPtr->lSelMax;
1762 case TBM_GETSELSTART:
1763 return infoPtr->lSelMin;
1765 case TBM_GETTHUMBLENGTH:
1766 return infoPtr->uThumbLen;
1768 case TBM_GETTHUMBRECT:
1769 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1772 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1775 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1777 case TBM_GETTOOLTIPS:
1778 return (LRESULT)infoPtr->hwndToolTip;
1780 case TBM_GETUNICODEFORMAT:
1781 return infoPtr->bUnicode;
1784 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1786 case TBM_SETLINESIZE:
1787 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1789 case TBM_SETPAGESIZE:
1790 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1793 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1796 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1798 case TBM_SETRANGEMAX:
1799 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1801 case TBM_SETRANGEMIN:
1802 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1805 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1808 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1810 case TBM_SETSELSTART:
1811 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1813 case TBM_SETTHUMBLENGTH:
1814 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1817 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1819 case TBM_SETTICFREQ:
1820 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1822 case TBM_SETTIPSIDE:
1823 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1825 case TBM_SETTOOLTIPS:
1826 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1828 case TBM_SETUNICODEFORMAT:
1829 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1832 case WM_CAPTURECHANGED:
1833 return TRACKBAR_CaptureChanged (infoPtr);
1836 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1839 return TRACKBAR_Destroy (infoPtr);
1841 /* case WM_ENABLE: */
1847 return DLGC_WANTARROWS;
1850 return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
1853 return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
1856 return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
1858 case WM_LBUTTONDOWN:
1859 return TRACKBAR_LButtonDown (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1862 return TRACKBAR_LButtonUp (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1865 infoPtr->flags &= ~TB_THUMB_HOT;
1866 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1870 return TRACKBAR_MouseMove (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1873 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1876 return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
1879 return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
1881 case WM_THEMECHANGED:
1882 return theme_changed (infoPtr);
1885 return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
1887 case WM_WININICHANGE:
1888 return TRACKBAR_InitializeThumb (infoPtr);
1891 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1892 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
1893 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1898 void TRACKBAR_Register (void)
1902 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1903 wndClass.style = CS_GLOBALCLASS;
1904 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1905 wndClass.cbClsExtra = 0;
1906 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1907 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1908 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1909 wndClass.lpszClassName = TRACKBAR_CLASSW;
1911 RegisterClassW (&wndClass);
1915 void TRACKBAR_Unregister (void)
1917 UnregisterClassW (TRACKBAR_CLASSW, NULL);