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(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 inline static void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
265 if (infoPtr->lPos == infoPtr->lRangeMin) return;
266 infoPtr->lPos -= infoPtr->lLineSize;
267 if (infoPtr->lPos < infoPtr->lRangeMin)
268 infoPtr->lPos = infoPtr->lRangeMin;
269 notify_with_scroll (infoPtr, TB_LINEUP);
272 inline static void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
274 if (infoPtr->lPos == infoPtr->lRangeMax) return;
275 infoPtr->lPos += infoPtr->lLineSize;
276 if (infoPtr->lPos > infoPtr->lRangeMax)
277 infoPtr->lPos = infoPtr->lRangeMax;
278 notify_with_scroll (infoPtr, TB_LINEDOWN);
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=%d, top=%d, right=%d, bottom=%d]\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=%d, y=%d, dir=%d\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;
585 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
589 int part = (dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
590 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
592 /* create the pen to draw the tics with */
593 hTicPen = CreatePenIndirect(&ticPen);
594 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
596 /* actually draw the tics */
597 for (i=0; i<infoPtr->uNumTics; i++)
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
600 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
601 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
603 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
604 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
605 ticFlags | TIC_SELECTIONMARKMIN);
606 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
607 ticFlags | TIC_SELECTIONMARKMAX);
610 /* clean up the pen, if we created one */
612 SelectObject(hdc, hOldPen);
613 DeleteObject(hTicPen);
618 TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
622 RECT thumb = infoPtr->rcThumb;
628 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
634 if (dwStyle & TBS_BOTH)
635 partId = (dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
636 else if (dwStyle & TBS_LEFT)
637 partId = (dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
639 partId = (dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
641 if (dwStyle & WS_DISABLED)
642 stateId = TUS_DISABLED;
643 else if (infoPtr->flags & TB_DRAG_MODE)
644 stateId = TUS_PRESSED;
645 else if (infoPtr->flags & TB_THUMB_HOT)
648 stateId = TUS_NORMAL;
650 DrawThemeBackground (theme, hdc, partId, stateId, &thumb, 0);
655 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
656 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
657 SetPolyFillMode (hdc, WINDING);
659 if (dwStyle & TBS_BOTH)
661 points[0].x=thumb.right;
662 points[0].y=thumb.top;
663 points[1].x=thumb.right;
664 points[1].y=thumb.bottom;
665 points[2].x=thumb.left;
666 points[2].y=thumb.bottom;
667 points[3].x=thumb.left;
668 points[3].y=thumb.top;
669 points[4].x=points[0].x;
670 points[4].y=points[0].y;
676 if (dwStyle & TBS_VERT)
678 PointDepth = (thumb.bottom - thumb.top) / 2;
679 if (dwStyle & TBS_LEFT)
681 points[0].x=thumb.right;
682 points[0].y=thumb.top;
683 points[1].x=thumb.right;
684 points[1].y=thumb.bottom;
685 points[2].x=thumb.left + PointDepth;
686 points[2].y=thumb.bottom;
687 points[3].x=thumb.left;
688 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
689 points[4].x=thumb.left + PointDepth;
690 points[4].y=thumb.top;
691 points[5].x=points[0].x;
692 points[5].y=points[0].y;
697 points[0].x=thumb.right;
698 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
699 points[1].x=thumb.right - PointDepth;
700 points[1].y=thumb.bottom;
701 points[2].x=thumb.left;
702 points[2].y=thumb.bottom;
703 points[3].x=thumb.left;
704 points[3].y=thumb.top;
705 points[4].x=thumb.right - PointDepth;
706 points[4].y=thumb.top;
707 points[5].x=points[0].x;
708 points[5].y=points[0].y;
713 PointDepth = (thumb.right - thumb.left) / 2;
714 if (dwStyle & TBS_TOP)
716 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
717 points[0].y=thumb.top;
718 points[1].x=thumb.right;
719 points[1].y=thumb.top + PointDepth;
720 points[2].x=thumb.right;
721 points[2].y=thumb.bottom;
722 points[3].x=thumb.left;
723 points[3].y=thumb.bottom;
724 points[4].x=thumb.left;
725 points[4].y=thumb.top + PointDepth;
726 points[5].x=points[0].x;
727 points[5].y=points[0].y;
732 points[0].x=thumb.right;
733 points[0].y=thumb.top;
734 points[1].x=thumb.right;
735 points[1].y=thumb.bottom - PointDepth;
736 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
737 points[2].y=thumb.bottom;
738 points[3].x=thumb.left;
739 points[3].y=thumb.bottom - PointDepth;
740 points[4].x=thumb.left;
741 points[4].y=thumb.top;
742 points[5].x=points[0].x;
743 points[5].y=points[0].y;
749 /* Draw the thumb now */
750 Polygon (hdc, points, PointCount);
751 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
752 Polyline(hdc,points, BlackUntil);
753 SelectObject(hdc, GetStockObject(WHITE_PEN));
754 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
755 SelectObject(hdc, oldpen);
756 SelectObject(hdc, oldbr);
761 TRACKBAR_ActivateToolTip (TRACKBAR_INFO *infoPtr, BOOL fShow)
765 if (!infoPtr->hwndToolTip) return;
767 ZeroMemory(&ti, sizeof(ti));
768 ti.cbSize = sizeof(ti);
769 ti.hwnd = infoPtr->hwndSelf;
771 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
776 TRACKBAR_UpdateToolTip (TRACKBAR_INFO *infoPtr)
778 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
780 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
786 if (!infoPtr->hwndToolTip) return;
788 ZeroMemory(&ti, sizeof(ti));
789 ti.cbSize = sizeof(ti);
790 ti.hwnd = infoPtr->hwndSelf;
791 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
793 wsprintfW (buf, fmt, infoPtr->lPos);
795 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
797 GetClientRect (infoPtr->hwndSelf, &rcClient);
798 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
799 if (dwStyle & TBS_VERT) {
800 if (infoPtr->fLocation == TBTS_LEFT)
801 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
803 pt.x = rcClient.right + TOOLTIP_OFFSET;
804 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
806 if (infoPtr->fLocation == TBTS_TOP)
807 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
809 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
810 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
812 ClientToScreen(infoPtr->hwndSelf, &pt);
814 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
815 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
820 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
822 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
825 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 (GetWindowTheme (infoPtr->hwndSelf))
873 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, &rcClient);
875 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
876 if (gcdrf != CDRF_DODEFAULT)
877 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
881 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
882 nmcd.dwItemSpec = TBCD_CHANNEL;
883 nmcd.uItemState = CDIS_DEFAULT;
884 nmcd.rc = infoPtr->rcChannel;
885 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
886 } else icdrf = CDRF_DODEFAULT;
887 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
888 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
889 if (icdrf & CDRF_NOTIFYPOSTPAINT)
890 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
895 if (!(dwStyle & TBS_NOTICKS)) {
896 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
897 nmcd.dwItemSpec = TBCD_TICS;
898 nmcd.uItemState = CDIS_DEFAULT;
900 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
901 } else icdrf = CDRF_DODEFAULT;
902 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
903 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
904 if (icdrf & CDRF_NOTIFYPOSTPAINT)
905 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
910 if (!(dwStyle & TBS_NOTHUMB)) {
911 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
912 nmcd.dwItemSpec = TBCD_THUMB;
913 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
914 nmcd.rc = infoPtr->rcThumb;
915 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
916 } else icdrf = CDRF_DODEFAULT;
917 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
918 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
919 if (icdrf & CDRF_NOTIFYPOSTPAINT)
920 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
924 /* draw focus rectangle */
925 if (infoPtr->bFocussed) {
926 DrawFocusRect(hdc, &rcClient);
929 /* finish up the painting */
930 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
931 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
934 /* cleanup, if we rendered offscreen */
936 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
937 SelectObject(hdc, hOldBmp);
938 DeleteObject(hOffScreenBmp);
945 TRACKBAR_AlignBuddies (TRACKBAR_INFO *infoPtr)
947 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
948 HWND hwndParent = GetParent (infoPtr->hwndSelf);
949 RECT rcSelf, rcBuddy;
952 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
953 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
955 /* align buddy left or above */
956 if (infoPtr->hwndBuddyLA) {
957 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
958 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
960 if (dwStyle & TBS_VERT) {
961 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
962 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
963 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
966 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
967 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
968 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
971 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
972 SWP_NOZORDER | SWP_NOSIZE);
976 /* align buddy right or below */
977 if (infoPtr->hwndBuddyRB) {
978 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
979 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
981 if (dwStyle & TBS_VERT) {
982 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
983 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
988 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
989 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
991 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
992 SWP_NOZORDER | SWP_NOSIZE);
998 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1000 infoPtr->lSelMin = 0;
1001 infoPtr->lSelMax = 0;
1002 infoPtr->flags |= TB_SELECTIONCHANGED;
1004 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1011 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1013 if (infoPtr->tics) {
1014 Free (infoPtr->tics);
1015 infoPtr->tics = NULL;
1016 infoPtr->uNumTics = 0;
1019 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1025 inline static LRESULT
1026 TRACKBAR_GetChannelRect (TRACKBAR_INFO *infoPtr, LPRECT lprc)
1028 if (lprc == NULL) return 0;
1030 lprc->left = infoPtr->rcChannel.left;
1031 lprc->right = infoPtr->rcChannel.right;
1032 lprc->bottom = infoPtr->rcChannel.bottom;
1033 lprc->top = infoPtr->rcChannel.top;
1040 TRACKBAR_GetNumTics (TRACKBAR_INFO *infoPtr)
1042 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
1045 if(infoPtr->uNumTics == 0)
1048 return infoPtr->uNumTics + 1;
1052 static int comp_tics(const void *ap, const void *bp)
1054 const DWORD a = *(const DWORD *)ap;
1055 const DWORD b = *(const DWORD *)bp;
1057 TRACE("(a=%d, b=%d)\n", a, b);
1058 if (a < b) return -1;
1059 if (a > b) return 1;
1065 TRACKBAR_GetTic (TRACKBAR_INFO *infoPtr, INT iTic)
1067 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1070 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1071 return infoPtr->tics[iTic];
1076 TRACKBAR_GetTicPos (TRACKBAR_INFO *infoPtr, INT iTic)
1078 LONG range, width, pos, tic;
1081 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1084 tic = TRACKBAR_GetTic (infoPtr, iTic);
1085 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1086 if (range <= 0) range = 1;
1087 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1088 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1089 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1096 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1101 /* buddy is left or above */
1102 hwndTemp = infoPtr->hwndBuddyLA;
1103 infoPtr->hwndBuddyLA = hwndBuddy;
1106 /* buddy is right or below */
1107 hwndTemp = infoPtr->hwndBuddyRB;
1108 infoPtr->hwndBuddyRB = hwndBuddy;
1111 TRACKBAR_AlignBuddies (infoPtr);
1118 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1120 LONG lTemp = infoPtr->lLineSize;
1122 infoPtr->lLineSize = lLineSize;
1129 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1131 LONG lTemp = infoPtr->lPageSize;
1133 infoPtr->lPageSize = lPageSize;
1139 inline static LRESULT
1140 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1142 LONG oldPos = infoPtr->lPos;
1143 infoPtr->lPos = lPosition;
1145 if (infoPtr->lPos < infoPtr->lRangeMin)
1146 infoPtr->lPos = infoPtr->lRangeMin;
1148 if (infoPtr->lPos > infoPtr->lRangeMax)
1149 infoPtr->lPos = infoPtr->lRangeMax;
1150 infoPtr->flags |= TB_THUMBPOSCHANGED;
1152 if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1158 inline static LRESULT
1159 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1161 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1162 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1164 if (infoPtr->lPos < infoPtr->lRangeMin) {
1165 infoPtr->lPos = infoPtr->lRangeMin;
1166 infoPtr->flags |= TB_THUMBPOSCHANGED;
1169 if (infoPtr->lPos > infoPtr->lRangeMax) {
1170 infoPtr->lPos = infoPtr->lRangeMax;
1171 infoPtr->flags |= TB_THUMBPOSCHANGED;
1174 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1175 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1177 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1183 inline static LRESULT
1184 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1186 infoPtr->lRangeMax = lMax;
1187 if (infoPtr->lPos > infoPtr->lRangeMax) {
1188 infoPtr->lPos = infoPtr->lRangeMax;
1189 infoPtr->flags |= TB_THUMBPOSCHANGED;
1192 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1193 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1195 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1201 inline static LRESULT
1202 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1204 infoPtr->lRangeMin = lMin;
1205 if (infoPtr->lPos < infoPtr->lRangeMin) {
1206 infoPtr->lPos = infoPtr->lRangeMin;
1207 infoPtr->flags |= TB_THUMBPOSCHANGED;
1210 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1211 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1213 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1219 inline static LRESULT
1220 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1222 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1223 infoPtr->lSelMin = 0;
1224 infoPtr->lSelMax = 0;
1228 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1229 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1230 infoPtr->flags |= TB_SELECTIONCHANGED;
1232 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1233 infoPtr->lSelMin = infoPtr->lRangeMin;
1234 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1235 infoPtr->lSelMax = infoPtr->lRangeMax;
1237 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1243 inline static LRESULT
1244 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1246 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1247 infoPtr->lSelMax = 0;
1251 infoPtr->lSelMax = lEnd;
1252 infoPtr->flags |= TB_SELECTIONCHANGED;
1254 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1255 infoPtr->lSelMax = infoPtr->lRangeMax;
1257 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1263 inline static LRESULT
1264 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1266 if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){
1267 infoPtr->lSelMin = 0;
1271 infoPtr->lSelMin = lStart;
1272 infoPtr->flags |=TB_SELECTIONCHANGED;
1274 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1275 infoPtr->lSelMin = infoPtr->lRangeMin;
1277 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1283 inline static LRESULT
1284 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1286 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) {
1287 infoPtr->uThumbLen = iLength;
1288 infoPtr->flags |= TB_THUMBSIZECHANGED;
1289 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1296 inline static LRESULT
1297 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1299 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1302 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1305 TRACE("lPos=%d\n", lPos);
1307 infoPtr->uNumTics++;
1308 infoPtr->tics=ReAlloc( infoPtr->tics,
1309 (infoPtr->uNumTics)*sizeof (DWORD));
1310 if (!infoPtr->tics) {
1311 infoPtr->uNumTics = 0;
1312 notify(infoPtr, NM_OUTOFMEMORY);
1315 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1317 TRACKBAR_InvalidateAll(infoPtr);
1323 inline static LRESULT
1324 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1326 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1327 infoPtr->uTicFreq = wFreq;
1328 TRACKBAR_RecalculateTics (infoPtr);
1329 TRACKBAR_InvalidateAll(infoPtr);
1337 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1339 INT fTemp = infoPtr->fLocation;
1341 infoPtr->fLocation = fLocation;
1347 inline static LRESULT
1348 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1350 infoPtr->hwndToolTip = hwndTT;
1357 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1359 BOOL bTemp = infoPtr->bUnicode;
1361 infoPtr->bUnicode = fUnicode;
1368 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1370 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1372 int clientWidth, clientMetric;
1374 /* initial thumb length */
1375 clientMetric = (dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1376 GetClientRect(infoPtr->hwndSelf,&rect);
1377 if (dwStyle & TBS_VERT) {
1378 clientWidth = rect.right - rect.left;
1380 clientWidth = rect.bottom - rect.top;
1382 if (clientWidth >= clientMetric)
1383 infoPtr->uThumbLen = clientMetric;
1385 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1387 TRACKBAR_CalcChannel (infoPtr);
1388 TRACKBAR_UpdateThumb (infoPtr);
1389 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1396 TRACKBAR_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
1398 TRACKBAR_INFO *infoPtr;
1401 infoPtr = (TRACKBAR_INFO *)Alloc (sizeof(TRACKBAR_INFO));
1402 if (!infoPtr) return -1;
1403 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1405 /* set default values */
1406 infoPtr->hwndSelf = hwnd;
1407 infoPtr->lRangeMin = 0;
1408 infoPtr->lRangeMax = 100;
1409 infoPtr->lLineSize = 1;
1410 infoPtr->lPageSize = 20;
1411 infoPtr->lSelMin = 0;
1412 infoPtr->lSelMax = 0;
1414 infoPtr->fLocation = -1;
1415 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1416 infoPtr->uTicFreq = 1;
1417 infoPtr->tics = NULL;
1418 infoPtr->hwndNotify= lpcs->hwndParent;
1420 TRACKBAR_InitializeThumb (infoPtr);
1422 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1424 /* Create tooltip control */
1425 if (dwStyle & TBS_TOOLTIPS) {
1427 infoPtr->hwndToolTip =
1428 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1429 CW_USEDEFAULT, CW_USEDEFAULT,
1430 CW_USEDEFAULT, CW_USEDEFAULT,
1433 if (infoPtr->hwndToolTip) {
1435 ZeroMemory (&ti, sizeof(ti));
1436 ti.cbSize = sizeof(ti);
1437 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1440 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1444 OpenThemeData (hwnd, themeClass);
1451 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1453 /* delete tooltip control */
1454 if (infoPtr->hwndToolTip)
1455 DestroyWindow (infoPtr->hwndToolTip);
1458 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1459 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1465 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
1468 infoPtr->bFocussed = FALSE;
1469 TRACKBAR_InvalidateAll(infoPtr);
1475 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1482 SetFocus(infoPtr->hwndSelf);
1484 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1485 infoPtr->flags |= TB_DRAG_MODE;
1486 SetCapture (infoPtr->hwndSelf);
1487 TRACKBAR_UpdateToolTip (infoPtr);
1488 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1489 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1491 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1492 if (dir == 0) return 0;
1493 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1494 TRACKBAR_AutoPage (infoPtr, clickPoint);
1495 SetCapture (infoPtr->hwndSelf);
1496 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1504 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1506 if (infoPtr->flags & TB_DRAG_MODE) {
1507 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1508 notify_with_scroll (infoPtr, TB_ENDTRACK);
1509 infoPtr->flags &= ~TB_DRAG_MODE;
1511 notify(infoPtr, NM_RELEASEDCAPTURE);
1512 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1513 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1515 if (infoPtr->flags & TB_AUTO_PAGE) {
1516 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1517 infoPtr->flags &= ~TB_AUTO_PAGE;
1518 notify_with_scroll (infoPtr, TB_ENDTRACK);
1520 notify(infoPtr, NM_RELEASEDCAPTURE);
1528 TRACKBAR_CaptureChanged (TRACKBAR_INFO *infoPtr)
1530 notify_with_scroll (infoPtr, TB_ENDTRACK);
1536 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1539 TRACKBAR_Refresh(infoPtr, hdc);
1542 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1543 TRACKBAR_Refresh (infoPtr, hdc);
1544 EndPaint (infoPtr->hwndSelf, &ps);
1552 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
1555 infoPtr->bFocussed = TRUE;
1556 TRACKBAR_InvalidateAll(infoPtr);
1563 TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
1565 TRACKBAR_InitializeThumb (infoPtr);
1566 TRACKBAR_AlignBuddies (infoPtr);
1573 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, TIMERPROC *tmrpc)
1575 if (infoPtr->flags & TB_AUTO_PAGE) {
1577 if (GetCursorPos(&pt))
1578 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1579 TRACKBAR_AutoPage(infoPtr, pt);
1585 /* update theme after a WM_THEMECHANGED message */
1586 static LRESULT theme_changed (TRACKBAR_INFO* infoPtr)
1588 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1589 CloseThemeData (theme);
1590 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
1596 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, INT x, INT y)
1598 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1599 INT clickPlace = (dwStyle & TBS_VERT) ? y : x;
1600 LONG dragPos, oldPos = infoPtr->lPos;
1602 TRACE("(x=%d. y=%d)\n", x, y);
1604 if (infoPtr->flags & TB_AUTO_PAGE) {
1608 TRACKBAR_AutoPage (infoPtr, pt);
1612 if (!(infoPtr->flags & TB_DRAG_MODE))
1614 if (GetWindowTheme (infoPtr->hwndSelf))
1616 DWORD oldFlags = infoPtr->flags;
1620 if (PtInRect (&infoPtr->rcThumb, pt))
1622 TRACKMOUSEEVENT tme;
1623 tme.cbSize = sizeof( tme );
1624 tme.dwFlags = TME_LEAVE;
1625 tme.hwndTrack = infoPtr->hwndSelf;
1626 TrackMouseEvent( &tme );
1627 infoPtr->flags |= TB_THUMB_HOT;
1631 TRACKMOUSEEVENT tme;
1632 tme.cbSize = sizeof( tme );
1633 tme.dwFlags = TME_CANCEL;
1634 tme.hwndTrack = infoPtr->hwndSelf;
1635 TrackMouseEvent( &tme );
1636 infoPtr->flags &= ~TB_THUMB_HOT;
1638 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1643 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1644 dwStyle & TBS_VERT);
1645 if (dragPos == oldPos) return TRUE;
1647 infoPtr->lPos = dragPos;
1649 infoPtr->flags |= TB_THUMBPOSCHANGED;
1650 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1653 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1654 UpdateWindow (infoPtr->hwndSelf);
1660 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1662 DWORD style = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1663 BOOL downIsLeft = style & TBS_DOWNISLEFT;
1664 BOOL vert = style & TBS_VERT;
1665 LONG pos = infoPtr->lPos;
1667 TRACE("%x\n", nVirtKey);
1671 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1672 else TRACKBAR_LineUp(infoPtr);
1675 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1676 else TRACKBAR_LineUp(infoPtr);
1679 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1680 else TRACKBAR_LineDown(infoPtr);
1683 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1684 else TRACKBAR_LineDown(infoPtr);
1687 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1688 else TRACKBAR_PageDown(infoPtr);
1691 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1692 else TRACKBAR_PageUp(infoPtr);
1695 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1696 infoPtr->lPos = infoPtr->lRangeMin;
1697 notify_with_scroll (infoPtr, TB_TOP);
1700 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1701 infoPtr->lPos = infoPtr->lRangeMax;
1702 notify_with_scroll (infoPtr, TB_BOTTOM);
1706 if (pos != infoPtr->lPos) {
1707 infoPtr->flags |=TB_THUMBPOSCHANGED;
1708 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1716 TRACKBAR_KeyUp (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1727 notify_with_scroll (infoPtr, TB_ENDTRACK);
1733 static LRESULT WINAPI
1734 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1736 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1738 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1740 if (!infoPtr && (uMsg != WM_CREATE))
1741 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1746 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1749 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1752 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1754 case TBM_GETCHANNELRECT:
1755 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1757 case TBM_GETLINESIZE:
1758 return infoPtr->lLineSize;
1760 case TBM_GETNUMTICS:
1761 return TRACKBAR_GetNumTics (infoPtr);
1763 case TBM_GETPAGESIZE:
1764 return infoPtr->lPageSize;
1767 return infoPtr->lPos;
1770 return (LRESULT)infoPtr->tics;
1772 case TBM_GETRANGEMAX:
1773 return infoPtr->lRangeMax;
1775 case TBM_GETRANGEMIN:
1776 return infoPtr->lRangeMin;
1779 return infoPtr->lSelMax;
1781 case TBM_GETSELSTART:
1782 return infoPtr->lSelMin;
1784 case TBM_GETTHUMBLENGTH:
1785 return infoPtr->uThumbLen;
1787 case TBM_GETTHUMBRECT:
1788 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1791 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1794 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1796 case TBM_GETTOOLTIPS:
1797 return (LRESULT)infoPtr->hwndToolTip;
1799 case TBM_GETUNICODEFORMAT:
1800 return infoPtr->bUnicode;
1803 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1805 case TBM_SETLINESIZE:
1806 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1808 case TBM_SETPAGESIZE:
1809 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1812 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1815 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1817 case TBM_SETRANGEMAX:
1818 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1820 case TBM_SETRANGEMIN:
1821 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1824 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1827 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1829 case TBM_SETSELSTART:
1830 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1832 case TBM_SETTHUMBLENGTH:
1833 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1836 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1838 case TBM_SETTICFREQ:
1839 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1841 case TBM_SETTIPSIDE:
1842 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1844 case TBM_SETTOOLTIPS:
1845 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1847 case TBM_SETUNICODEFORMAT:
1848 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1851 case WM_CAPTURECHANGED:
1852 return TRACKBAR_CaptureChanged (infoPtr);
1855 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1858 return TRACKBAR_Destroy (infoPtr);
1860 /* case WM_ENABLE: */
1866 return DLGC_WANTARROWS;
1869 return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
1872 return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
1875 return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
1877 case WM_LBUTTONDOWN:
1878 return TRACKBAR_LButtonDown (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1881 return TRACKBAR_LButtonUp (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1884 infoPtr->flags &= ~TB_THUMB_HOT;
1885 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1889 return TRACKBAR_MouseMove (infoPtr, wParam, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1891 case WM_PRINTCLIENT:
1893 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1896 return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
1899 return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
1901 case WM_THEMECHANGED:
1902 return theme_changed (infoPtr);
1905 return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
1907 case WM_WININICHANGE:
1908 return TRACKBAR_InitializeThumb (infoPtr);
1911 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1912 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
1913 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1918 void TRACKBAR_Register (void)
1922 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1923 wndClass.style = CS_GLOBALCLASS;
1924 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
1925 wndClass.cbClsExtra = 0;
1926 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1927 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1928 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1929 wndClass.lpszClassName = TRACKBAR_CLASSW;
1931 RegisterClassW (&wndClass);
1935 void TRACKBAR_Unregister (void)
1937 UnregisterClassW (TRACKBAR_CLASSW, NULL);