4 * Copyright 1998, 1999 Eric Kohl <ekohl@abo.rhein-zeitung.de>
5 * Copyright 1998, 1999 Alex Priem <alexp@sci.kun.nl>
6 * Copyright 2002 Dimitrie O. Paun <dimi@bigfoot.com>
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.
39 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
71 DEFINE_COMMON_NOTIFICATIONS(TRACKBAR_INFO, hwndSelf);
73 #define TB_REFRESH_TIMER 1
74 #define TB_REFRESH_DELAY 500
76 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
78 /* Used by TRACKBAR_Refresh to find out which parts of the control
79 need to be recalculated */
81 #define TB_THUMBPOSCHANGED 1
82 #define TB_THUMBSIZECHANGED 2
83 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
84 #define TB_SELECTIONCHANGED 4
85 #define TB_DRAG_MODE 8 /* we're dragging the slider */
86 #define TB_AUTO_PAGE_LEFT 16
87 #define TB_AUTO_PAGE_RIGHT 32
88 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
90 /* helper defines for TRACKBAR_DrawTic */
92 #define TIC_SELECTIONMARKMAX 0x80
93 #define TIC_SELECTIONMARKMIN 0x100
94 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
96 static BOOL TRACKBAR_SendNotify (TRACKBAR_INFO *infoPtr, UINT code);
99 notify_customdraw(NMCUSTOMDRAW *pnmcd, int stage)
101 pnmcd->dwDrawStage = stage;
102 return SendMessageW (GetParent(pnmcd->hdr.hwndFrom), WM_NOTIFY,
103 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
106 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
110 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin)
111 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
114 COMCTL32_Free (infoPtr->tics);
115 infoPtr->tics = NULL;
116 infoPtr->uNumTics = 0;
120 if (nrTics != infoPtr->uNumTics) {
121 infoPtr->tics=COMCTL32_ReAlloc (infoPtr->tics,
122 (nrTics+1)*sizeof (DWORD));
123 if (!infoPtr->tics) {
124 infoPtr->uNumTics = 0;
125 notify_outofmemory(infoPtr);
128 infoPtr->uNumTics = nrTics;
131 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
132 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
133 infoPtr->tics[i] = tic;
136 /* converts from physical (mouse) position to logical position
137 (in range of trackbar) */
140 TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO *infoPtr, int place,
143 double range, width, pos;
145 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
147 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
148 pos = (range*(place - infoPtr->rcChannel.top)) / width;
150 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
151 pos = (range*(place - infoPtr->rcChannel.left)) / width;
153 pos += infoPtr->lRangeMin;
154 if (pos > infoPtr->lRangeMax)
155 pos = infoPtr->lRangeMax;
156 else if (pos < infoPtr->lRangeMin)
157 pos = infoPtr->lRangeMin;
159 TRACE("%.2f\n", pos);
160 return (LONG)(pos + 0.5);
164 /* return: 0> prev, 0 none, >0 next */
166 TRACKBAR_GetAutoPageDirection (TRACKBAR_INFO *infoPtr, POINT clickPoint)
168 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
171 if (dwStyle & TBS_VERT) {
172 pageRect.top = infoPtr->rcChannel.top;
173 pageRect.bottom = infoPtr->rcChannel.bottom;
174 pageRect.left = infoPtr->rcThumb.left;
175 pageRect.right = infoPtr->rcThumb.right;
177 pageRect.top = infoPtr->rcThumb.top;
178 pageRect.bottom = infoPtr->rcThumb.bottom;
179 pageRect.left = infoPtr->rcChannel.left;
180 pageRect.right = infoPtr->rcChannel.right;
184 if (PtInRect(&pageRect, clickPoint))
186 int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
188 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace,
190 return clickPos - infoPtr->lPos;
197 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
199 if (infoPtr->lPos == infoPtr->lRangeMax) return;
201 infoPtr->lPos += infoPtr->lPageSize;
202 if (infoPtr->lPos > infoPtr->lRangeMax)
203 infoPtr->lPos = infoPtr->lRangeMax;
204 TRACKBAR_SendNotify (infoPtr, TB_PAGEUP);
209 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
211 if (infoPtr->lPos == infoPtr->lRangeMin) return;
213 infoPtr->lPos -= infoPtr->lPageSize;
214 if (infoPtr->lPos < infoPtr->lRangeMin)
215 infoPtr->lPos = infoPtr->lRangeMin;
216 TRACKBAR_SendNotify (infoPtr, TB_PAGEDOWN);
220 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
222 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
223 INT cyChannel, offsetthumb, offsetedge;
224 RECT lpRect, *channel = & infoPtr->rcChannel;
226 GetClientRect (infoPtr->hwndSelf, &lpRect);
228 offsetthumb = (int)(infoPtr->uThumbLen/4.5);
229 offsetedge = offsetthumb + 3;
230 cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? (offsetthumb+1)*3 : 4;
232 if (dwStyle & TBS_VERT) {
233 channel->top = lpRect.top + offsetedge;
234 channel->bottom = lpRect.bottom - offsetedge;
235 channel->left = lpRect.left + offsetthumb;
236 if (dwStyle & (TBS_BOTH | TBS_LEFT)) channel->left += 8;
237 channel->right = channel->left + cyChannel;
239 channel->left = lpRect.left + offsetedge;
240 channel->right = lpRect.right - offsetedge;
241 channel->top = lpRect.top + offsetthumb;
242 if (dwStyle & (TBS_BOTH | TBS_TOP)) channel->top += 8;
243 channel->bottom = channel->top + cyChannel;
248 TRACKBAR_CalcThumb (TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
250 int range, width, thumbdepth;
251 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
253 range=infoPtr->lRangeMax - infoPtr->lRangeMin;
254 thumbdepth = ((int)(infoPtr->uThumbLen / 4.5) * 2) + 2;
256 if (!range) range = 1;
258 if (dwStyle & TBS_VERT)
260 width=infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
262 if (dwStyle & (TBS_BOTH | TBS_LEFT))
266 thumb->right = thumb -> left + infoPtr->uThumbLen;
267 thumb->top = infoPtr->rcChannel.top +
268 (width*(lPos - infoPtr->lRangeMin))/range -
270 thumb->bottom = thumb->top + thumbdepth;
274 width=infoPtr->rcChannel.right - infoPtr->rcChannel.left;
276 thumb->left = infoPtr->rcChannel.left +
277 (width*(lPos - infoPtr->lRangeMin))/range -
279 thumb->right = thumb->left + thumbdepth;
280 if (dwStyle & (TBS_BOTH | TBS_TOP))
284 thumb->bottom = thumb->top + infoPtr->uThumbLen;
289 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
291 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
295 TRACKBAR_InvalidateAll(TRACKBAR_INFO * infoPtr)
297 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
301 TRACKBAR_InvalidateThumb (TRACKBAR_INFO *infoPtr, LONG thumbPos)
305 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
306 InflateRect(&rcThumb, 1, 1);
307 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
311 TRACKBAR_InvalidateThumbMove (TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
313 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
314 if (newPos != oldPos)
315 TRACKBAR_InvalidateThumb (infoPtr, newPos);
319 TRACKBAR_HasSelection (TRACKBAR_INFO *infoPtr)
321 return infoPtr->lSelMin != infoPtr->lSelMax;
325 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
327 RECT *selection = &infoPtr->rcSelection;
328 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
331 SetRectEmpty (selection);
333 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) {
334 int height = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
335 selection->top = infoPtr->rcChannel.top +
336 (height*infoPtr->lSelMin)/range;
337 selection->bottom = infoPtr->rcChannel.top +
338 (height*infoPtr->lSelMax)/range;
339 selection->left = infoPtr->rcChannel.left + 3;
340 selection->right = infoPtr->rcChannel.right - 3;
342 int width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
343 selection->left = infoPtr->rcChannel.left +
344 (width*infoPtr->lSelMin)/range;
345 selection->right = infoPtr->rcChannel.left +
346 (width*infoPtr->lSelMax)/range;
347 selection->top = infoPtr->rcChannel.top + 3;
348 selection->bottom = infoPtr->rcChannel.bottom - 3;
352 TRACE("selection[left=%d, top=%d, right=%d, bottom=%d]\n",
353 selection->left, selection->top, selection->right, selection->bottom);
357 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
359 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
360 LONG prevPos = infoPtr->lPos;
362 TRACE("x=%ld, y=%ld, dir=%ld\n", clickPoint.x, clickPoint.y, dir);
364 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
365 TRACKBAR_PageUp(infoPtr);
366 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
367 TRACKBAR_PageDown(infoPtr);
370 infoPtr->flags |= TB_THUMBPOSCHANGED;
371 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
376 /* Trackbar drawing code. I like my spaghetti done milanese. */
379 TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
381 RECT rcChannel = infoPtr->rcChannel;
383 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
384 if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
385 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
386 if (TRACKBAR_HasSelection(infoPtr))
387 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
392 TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
394 int x, y, ox, oy, range, side, offset = 5, indent = 0, len = 3;
399 GetClientRect(infoPtr->hwndSelf, &rcTics);
400 if (flags & TBS_VERT) {
401 rcTics.top = infoPtr->rcChannel.top;
402 rcTics.bottom = infoPtr->rcChannel.bottom;
404 rcTics.left = infoPtr->rcChannel.left;
405 rcTics.right = infoPtr->rcChannel.right;
408 if (flags & (TBS_TOP | TBS_LEFT)) {
418 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
420 range = 1; /* to avoid division by zero */
422 if (flags & TIC_SELECTIONMARK) {
423 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
424 } else if (flags & TIC_EDGE) {
428 if (flags & TBS_VERT) {
429 int height = rcTics.bottom = rcTics.top;
430 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
431 x -= (offset + 2) * side;
434 int width = rcTics.right - rcTics.left;
435 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
437 y -= (offset + 2) * side;
442 MoveToEx(hdc, x, y, 0);
443 if (flags & TBS_VERT) x += len * side;
444 else y += len * side;
447 if (flags & TIC_SELECTIONMARK) {
448 if (flags & TBS_VERT) {
453 MoveToEx(hdc, x, y, 0);
454 if (flags & TBS_VERT) {
467 TRACKBAR_DrawTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
469 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
470 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
472 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
473 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags);
477 TRACKBAR_DrawTics (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
479 int i, ticFlags = dwStyle & 0x0f;
480 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
481 HPEN hOldPen, hTicPen;
483 /* create the pen to draw the tics with */
484 hTicPen = CreatePenIndirect(&ticPen);
485 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
487 /* actually draw the tics */
488 for (i=0; i<infoPtr->uNumTics; i++)
489 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
491 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
492 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
494 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
495 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
496 ticFlags | TIC_SELECTIONMARKMIN);
497 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
498 ticFlags | TIC_SELECTIONMARKMAX);
501 /* clean up the pen, if we created one */
503 SelectObject(hdc, hOldPen);
504 DeleteObject(hTicPen);
509 TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
513 RECT thumb = infoPtr->rcThumb;
519 static INT PointDepth = 4;
521 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
522 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
523 SetPolyFillMode (hdc, WINDING);
525 if (dwStyle & TBS_BOTH)
527 points[0].x=thumb.right;
528 points[0].y=thumb.top;
529 points[1].x=thumb.right;
530 points[1].y=thumb.bottom;
531 points[2].x=thumb.left;
532 points[2].y=thumb.bottom;
533 points[3].x=thumb.left;
534 points[3].y=thumb.top;
535 points[4].x=points[0].x;
536 points[4].y=points[0].y;
542 if (dwStyle & TBS_VERT)
544 if (dwStyle & TBS_LEFT)
546 points[0].x=thumb.right;
547 points[0].y=thumb.top;
548 points[1].x=thumb.right;
549 points[1].y=thumb.bottom;
550 points[2].x=thumb.left + PointDepth;
551 points[2].y=thumb.bottom;
552 points[3].x=thumb.left;
553 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top;
554 points[4].x=thumb.left + PointDepth;
555 points[4].y=thumb.top;
556 points[5].x=points[0].x;
557 points[5].y=points[0].y;
562 points[0].x=thumb.right;
563 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top;
564 points[1].x=thumb.right - PointDepth;
565 points[1].y=thumb.bottom;
566 points[2].x=thumb.left;
567 points[2].y=thumb.bottom;
568 points[3].x=thumb.left;
569 points[3].y=thumb.top;
570 points[4].x=thumb.right - PointDepth;
571 points[4].y=thumb.top;
572 points[5].x=points[0].x;
573 points[5].y=points[0].y;
578 if (dwStyle & TBS_TOP)
580 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left ;
581 points[0].y=thumb.top;
582 points[1].x=thumb.right;
583 points[1].y=thumb.top + PointDepth;
584 points[2].x=thumb.right;
585 points[2].y=thumb.bottom;
586 points[3].x=thumb.left;
587 points[3].y=thumb.bottom;
588 points[4].x=thumb.left;
589 points[4].y=thumb.top + PointDepth;
590 points[5].x=points[0].x;
591 points[5].y=points[0].y;
596 points[0].x=thumb.right;
597 points[0].y=thumb.top;
598 points[1].x=thumb.right;
599 points[1].y=thumb.bottom - PointDepth;
600 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left ;
601 points[2].y=thumb.bottom;
602 points[3].x=thumb.left;
603 points[3].y=thumb.bottom - PointDepth;
604 points[4].x=thumb.left;
605 points[4].y=thumb.top;
606 points[5].x=points[0].x;
607 points[5].y=points[0].y;
613 /* Draw the thumb now */
614 Polygon (hdc, points, PointCount);
615 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
616 Polyline(hdc,points, BlackUntil);
617 SelectObject(hdc, GetStockObject(WHITE_PEN));
618 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
619 SelectObject(hdc, oldpen);
620 SelectObject(hdc, oldbr);
625 TRACKBAR_ActivateToolTip (TRACKBAR_INFO *infoPtr, BOOL fShow)
629 if (!infoPtr->hwndToolTip) return;
631 ZeroMemory(&ti, sizeof(ti));
632 ti.cbSize = sizeof(ti);
633 ti.hwnd = infoPtr->hwndSelf;
635 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
640 TRACKBAR_UpdateToolTip (TRACKBAR_INFO *infoPtr)
642 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
643 WCHAR buf[80], fmt[] = { '%', 'l', 'd', 0 };
649 if (!infoPtr->hwndToolTip) return;
651 ZeroMemory(&ti, sizeof(ti));
652 ti.cbSize = sizeof(ti);
653 ti.hwnd = infoPtr->hwndSelf;
654 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
656 wsprintfW (buf, fmt, infoPtr->lPos);
658 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
660 GetClientRect (infoPtr->hwndSelf, &rcClient);
661 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
662 if (dwStyle & TBS_VERT) {
663 if (infoPtr->fLocation == TBTS_LEFT)
664 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
666 pt.x = rcClient.right + TOOLTIP_OFFSET;
667 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
669 if (infoPtr->fLocation == TBTS_TOP)
670 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
672 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
673 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
675 ClientToScreen(infoPtr->hwndSelf, &pt);
677 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
678 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
683 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
685 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
688 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
692 if (infoPtr->flags & TB_THUMBCHANGED) {
693 TRACKBAR_UpdateThumb (infoPtr);
694 if (infoPtr->flags & TB_THUMBSIZECHANGED)
695 TRACKBAR_CalcChannel (infoPtr);
697 if (infoPtr->flags & TB_SELECTIONCHANGED)
698 TRACKBAR_CalcSelection (infoPtr);
700 if (infoPtr->flags & TB_DRAG_MODE)
701 TRACKBAR_UpdateToolTip (infoPtr);
703 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
705 GetClientRect (infoPtr->hwndSelf, &rcClient);
707 /* try to render offscreen, if we fail, carrry onscreen */
708 hdc = CreateCompatibleDC(hdcDst);
710 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
712 hOldBmp = SelectObject(hdc, hOffScreenBmp);
721 ZeroMemory(&nmcd, sizeof(nmcd));
722 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
723 nmcd.hdr.idFrom = GetWindowLongW (infoPtr->hwndSelf, GWL_ID);
724 nmcd.hdr.code = NM_CUSTOMDRAW;
727 /* start the paint cycle */
729 gcdrf = notify_customdraw(&nmcd, CDDS_PREPAINT);
730 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
732 /* Erase backbround */
733 if (gcdrf == CDRF_DODEFAULT ||
734 notify_customdraw(&nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
735 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
736 if (gcdrf != CDRF_DODEFAULT)
737 notify_customdraw(&nmcd, CDDS_POSTERASE);
741 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
742 nmcd.dwItemSpec = TBCD_CHANNEL;
743 nmcd.uItemState = CDIS_DEFAULT;
744 nmcd.rc = infoPtr->rcChannel;
745 icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
746 } else icdrf = CDRF_DODEFAULT;
747 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
748 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
749 if (icdrf & CDRF_NOTIFYPOSTPAINT)
750 notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
755 if (!(dwStyle & TBS_NOTICKS)) {
756 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
757 nmcd.dwItemSpec = TBCD_TICS;
758 nmcd.uItemState = CDIS_DEFAULT;
760 icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
761 } else icdrf = CDRF_DODEFAULT;
762 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
763 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
764 if (icdrf & CDRF_NOTIFYPOSTPAINT)
765 notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
770 if (!(dwStyle & TBS_NOTHUMB)) {
771 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
772 nmcd.dwItemSpec = TBCD_THUMB;
773 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
774 nmcd.rc = infoPtr->rcThumb;
775 icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
776 } else icdrf = CDRF_DODEFAULT;
777 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
778 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
779 if (icdrf & CDRF_NOTIFYPOSTPAINT)
780 notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
784 /* finish up the painting */
785 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
786 notify_customdraw(&nmcd, CDDS_POSTPAINT);
789 /* cleanup, if we rendered offscreen */
791 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
792 SelectObject(hdc, hOldBmp);
793 DeleteObject(hOffScreenBmp);
800 TRACKBAR_AlignBuddies (TRACKBAR_INFO *infoPtr)
802 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
803 HWND hwndParent = GetParent (infoPtr->hwndSelf);
804 RECT rcSelf, rcBuddy;
807 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
808 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
810 /* align buddy left or above */
811 if (infoPtr->hwndBuddyLA) {
812 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
813 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
815 if (dwStyle & TBS_VERT) {
816 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
817 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
818 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
821 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
822 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
823 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
826 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
827 SWP_NOZORDER | SWP_NOSIZE);
831 /* align buddy right or below */
832 if (infoPtr->hwndBuddyRB) {
833 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
834 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
836 if (dwStyle & TBS_VERT) {
837 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
838 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
843 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
844 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
846 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
847 SWP_NOZORDER | SWP_NOSIZE);
853 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
855 infoPtr->lSelMin = 0;
856 infoPtr->lSelMax = 0;
857 infoPtr->flags |= TB_SELECTIONCHANGED;
859 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
866 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
869 COMCTL32_Free (infoPtr->tics);
870 infoPtr->tics = NULL;
871 infoPtr->uNumTics = 0;
874 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
880 static LRESULT inline
881 TRACKBAR_GetChannelRect (TRACKBAR_INFO *infoPtr, LPRECT lprc)
883 if (lprc == NULL) return 0;
885 lprc->left = infoPtr->rcChannel.left;
886 lprc->right = infoPtr->rcChannel.right;
887 lprc->bottom = infoPtr->rcChannel.bottom;
888 lprc->top = infoPtr->rcChannel.top;
895 TRACKBAR_GetNumTics (TRACKBAR_INFO *infoPtr)
897 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
900 return infoPtr->uNumTics + 2;
904 static int comp_tics(const void *ap, const void *bp)
906 DWORD a = *((DWORD *)ap);
907 DWORD b = *((DWORD *)bp);
909 TRACE("(a=%ld, b=%ld)\n", a, b);
910 if (a < b) return -1;
917 TRACKBAR_GetTic (TRACKBAR_INFO *infoPtr, INT iTic)
919 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
922 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
923 return infoPtr->tics[iTic];
928 TRACKBAR_GetTicPos (TRACKBAR_INFO *infoPtr, INT iTic)
930 LONG range, width, pos, tic;
932 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
935 tic = TRACKBAR_GetTic (infoPtr, iTic);
936 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
937 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
938 pos = infoPtr->rcChannel.left + (width * tic) / range;
945 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
950 /* buddy is left or above */
951 hwndTemp = infoPtr->hwndBuddyLA;
952 infoPtr->hwndBuddyLA = hwndBuddy;
955 /* buddy is right or below */
956 hwndTemp = infoPtr->hwndBuddyRB;
957 infoPtr->hwndBuddyRB = hwndBuddy;
960 TRACKBAR_AlignBuddies (infoPtr);
967 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
969 LONG lTemp = infoPtr->lLineSize;
971 infoPtr->lLineSize = lLineSize;
978 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
980 LONG lTemp = infoPtr->lPageSize;
982 infoPtr->lPageSize = lPageSize;
988 static LRESULT inline
989 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
991 LONG oldPos = infoPtr->lPos;
992 infoPtr->lPos = lPosition;
994 if (infoPtr->lPos < infoPtr->lRangeMin)
995 infoPtr->lPos = infoPtr->lRangeMin;
997 if (infoPtr->lPos > infoPtr->lRangeMax)
998 infoPtr->lPos = infoPtr->lRangeMax;
999 infoPtr->flags |= TB_THUMBPOSCHANGED;
1001 if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1007 static LRESULT inline
1008 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1010 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1011 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1013 if (infoPtr->lPos < infoPtr->lRangeMin) {
1014 infoPtr->lPos = infoPtr->lRangeMin;
1015 infoPtr->flags |= TB_THUMBPOSCHANGED;
1018 if (infoPtr->lPos > infoPtr->lRangeMax) {
1019 infoPtr->lPos = infoPtr->lRangeMax;
1020 infoPtr->flags |= TB_THUMBPOSCHANGED;
1023 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1024 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1026 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1032 static LRESULT inline
1033 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1035 infoPtr->lRangeMax = lMax;
1036 if (infoPtr->lPos > infoPtr->lRangeMax) {
1037 infoPtr->lPos = infoPtr->lRangeMax;
1038 infoPtr->flags |= TB_THUMBPOSCHANGED;
1041 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1042 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1044 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1050 static LRESULT inline
1051 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1053 infoPtr->lRangeMin = lMin;
1054 if (infoPtr->lPos < infoPtr->lRangeMin) {
1055 infoPtr->lPos = infoPtr->lRangeMin;
1056 infoPtr->flags |= TB_THUMBPOSCHANGED;
1059 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1060 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1062 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1068 static LRESULT inline
1069 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1071 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1074 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1075 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1076 infoPtr->flags |= TB_SELECTIONCHANGED;
1078 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1079 infoPtr->lSelMin = infoPtr->lRangeMin;
1080 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1081 infoPtr->lSelMax = infoPtr->lRangeMax;
1083 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1089 static LRESULT inline
1090 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1092 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1095 infoPtr->lSelMax = lEnd;
1096 infoPtr->flags |= TB_SELECTIONCHANGED;
1098 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1099 infoPtr->lSelMax = infoPtr->lRangeMax;
1101 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1107 static LRESULT inline
1108 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1110 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1113 infoPtr->lSelMin = lStart;
1114 infoPtr->flags |=TB_SELECTIONCHANGED;
1116 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1117 infoPtr->lSelMin = infoPtr->lRangeMin;
1119 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1125 static LRESULT inline
1126 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1128 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH)
1129 infoPtr->uThumbLen = iLength;
1131 infoPtr->flags |= TB_THUMBSIZECHANGED;
1133 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1139 static LRESULT inline
1140 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1142 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1145 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1148 TRACE("lPos=%ld\n", lPos);
1150 infoPtr->uNumTics++;
1151 infoPtr->tics=COMCTL32_ReAlloc( infoPtr->tics,
1152 (infoPtr->uNumTics)*sizeof (DWORD));
1153 if (!infoPtr->tics) {
1154 infoPtr->uNumTics = 0;
1155 notify_outofmemory(infoPtr);
1158 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1160 TRACKBAR_InvalidateAll(infoPtr);
1166 static LRESULT inline
1167 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1169 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1170 infoPtr->uTicFreq = wFreq;
1171 TRACKBAR_RecalculateTics (infoPtr);
1172 TRACKBAR_InvalidateAll(infoPtr);
1180 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1182 INT fTemp = infoPtr->fLocation;
1184 infoPtr->fLocation = fLocation;
1190 static LRESULT inline
1191 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1193 infoPtr->hwndToolTip = hwndTT;
1200 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1202 BOOL bTemp = infoPtr->bUnicode;
1204 infoPtr->bUnicode = fUnicode;
1211 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1213 infoPtr->uThumbLen = 23; /* initial thumb length */
1215 TRACKBAR_CalcChannel (infoPtr);
1216 TRACKBAR_UpdateThumb (infoPtr);
1217 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1224 TRACKBAR_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
1226 TRACKBAR_INFO *infoPtr;
1227 DWORD oldStyle, newStyle;
1229 infoPtr = (TRACKBAR_INFO *)COMCTL32_Alloc (sizeof(TRACKBAR_INFO));
1230 if (!infoPtr) return -1;
1231 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
1233 /* set default values */
1234 infoPtr->hwndSelf = hwnd;
1235 infoPtr->lRangeMin = 0;
1236 infoPtr->lRangeMax = 100;
1237 infoPtr->lLineSize = 1;
1238 infoPtr->lPageSize = 20;
1239 infoPtr->lSelMin = 0;
1240 infoPtr->lSelMax = 0;
1242 infoPtr->fLocation = -1;
1243 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1244 infoPtr->uTicFreq = 1;
1245 infoPtr->tics = NULL;
1246 infoPtr->hwndNotify= GetParent (hwnd);
1248 TRACKBAR_InitializeThumb (infoPtr);
1250 oldStyle = newStyle = GetWindowLongW (hwnd, GWL_STYLE);
1251 if (oldStyle & TBS_VERT) {
1252 if (! (oldStyle & (TBS_LEFT | TBS_RIGHT | TBS_BOTH)) )
1253 newStyle |= TBS_RIGHT;
1255 if (! (oldStyle & (TBS_TOP | TBS_BOTTOM | TBS_BOTH)) )
1256 newStyle |= TBS_BOTTOM;
1258 if (newStyle != oldStyle)
1259 SetWindowLongW (hwnd, GWL_STYLE, newStyle);
1261 /* Create tooltip control */
1262 if (newStyle & TBS_TOOLTIPS) {
1264 infoPtr->hwndToolTip =
1265 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
1266 CW_USEDEFAULT, CW_USEDEFAULT,
1267 CW_USEDEFAULT, CW_USEDEFAULT,
1270 if (infoPtr->hwndToolTip) {
1272 notify_tooltipscreated(infoPtr);
1274 ZeroMemory (&ti, sizeof(ti));
1275 ti.cbSize = sizeof(ti);
1276 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1279 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1288 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1290 /* delete tooltip control */
1291 if (infoPtr->hwndToolTip)
1292 DestroyWindow (infoPtr->hwndToolTip);
1294 COMCTL32_Free (infoPtr);
1295 SetWindowLongW (infoPtr->hwndSelf, 0, 0);
1301 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
1305 TRACKBAR_InvalidateAll(infoPtr);
1311 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
1313 POINT clickPoint = { pts.x, pts.y };
1315 SetFocus(infoPtr->hwndSelf);
1317 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1318 infoPtr->flags |= TB_DRAG_MODE;
1319 SetCapture (infoPtr->hwndSelf);
1320 TRACKBAR_UpdateToolTip (infoPtr);
1321 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1322 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1324 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1325 if (dir == 0) return 0;
1326 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1327 TRACKBAR_AutoPage (infoPtr, clickPoint);
1328 SetCapture (infoPtr->hwndSelf);
1329 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1337 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
1339 if (infoPtr->flags & TB_DRAG_MODE) {
1340 TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
1341 infoPtr->flags &= ~TB_DRAG_MODE;
1343 notify_releasedcapture(infoPtr);
1344 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1345 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1347 if (infoPtr->flags & TB_AUTO_PAGE) {
1348 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1349 infoPtr->flags &= ~TB_AUTO_PAGE;
1351 notify_releasedcapture(infoPtr);
1359 TRACKBAR_CaptureChanged (TRACKBAR_INFO *infoPtr)
1361 TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
1367 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1370 TRACKBAR_Refresh(infoPtr, hdc);
1373 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1374 TRACKBAR_Refresh (infoPtr, hdc);
1375 EndPaint (infoPtr->hwndSelf, &ps);
1383 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
1387 TRACKBAR_InvalidateAll(infoPtr);
1394 TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
1396 TRACKBAR_CalcChannel (infoPtr);
1397 TRACKBAR_AlignBuddies (infoPtr);
1404 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, TIMERPROC *tmrpc)
1406 if (infoPtr->flags & TB_AUTO_PAGE) {
1408 if (GetCursorPos(&pt))
1409 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1410 TRACKBAR_AutoPage(infoPtr, pt);
1417 TRACKBAR_SendNotify (TRACKBAR_INFO *infoPtr, UINT code)
1419 BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT;
1421 TRACE("%x\n", code);
1423 return (BOOL) SendMessageW (GetParent (infoPtr->hwndSelf),
1424 bVert ? WM_VSCROLL : WM_HSCROLL,
1425 (WPARAM)code, (LPARAM)infoPtr->hwndSelf);
1430 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
1432 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1433 INT clickPlace = (dwStyle & TBS_VERT) ? pts.y : pts.x;
1434 DOUBLE dragPos, oldPos = infoPtr->lPos;
1436 TRACE("(x=%d. y=%d)\n", pts.x, pts.y);
1438 if (infoPtr->flags & TB_AUTO_PAGE) {
1440 POINTSTOPOINT(pt, pts);
1441 TRACKBAR_AutoPage (infoPtr, pt);
1445 if (!(infoPtr->flags & TB_DRAG_MODE)) return TRUE;
1447 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1448 dwStyle & TBS_VERT);
1449 if (dragPos > ((INT)dragPos) + 0.5) dragPos++;
1451 if (dragPos == oldPos) return TRUE;
1453 infoPtr->lPos = dragPos;
1455 infoPtr->flags |= TB_THUMBPOSCHANGED;
1456 TRACKBAR_SendNotify (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1459 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1460 UpdateWindow (infoPtr->hwndSelf);
1467 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1469 BOOL downIsLeft = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_DOWNISLEFT;
1470 LONG pos = infoPtr->lPos;
1472 TRACE("%x\n", nVirtKey);
1476 if (downIsLeft) goto step_right;
1479 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1480 infoPtr->lPos -= infoPtr->lLineSize;
1481 if (infoPtr->lPos < infoPtr->lRangeMin)
1482 infoPtr->lPos = infoPtr->lRangeMin;
1483 TRACKBAR_SendNotify (infoPtr, TB_LINEUP);
1486 if (downIsLeft) goto step_left;
1489 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1490 infoPtr->lPos += infoPtr->lLineSize;
1491 if (infoPtr->lPos > infoPtr->lRangeMax)
1492 infoPtr->lPos = infoPtr->lRangeMax;
1493 TRACKBAR_SendNotify (infoPtr, TB_LINEDOWN);
1496 if (downIsLeft) goto page_left;
1498 TRACKBAR_PageUp(infoPtr);
1501 if (downIsLeft) goto page_right;
1503 TRACKBAR_PageDown(infoPtr);
1506 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1507 infoPtr->lPos = infoPtr->lRangeMin;
1508 TRACKBAR_SendNotify (infoPtr, TB_TOP);
1511 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1512 infoPtr->lPos = infoPtr->lRangeMax;
1513 TRACKBAR_SendNotify (infoPtr, TB_BOTTOM);
1517 if (pos != infoPtr->lPos) {
1518 infoPtr->flags |=TB_THUMBPOSCHANGED;
1519 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1527 TRACKBAR_KeyUp (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1538 TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
1544 static LRESULT WINAPI
1545 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1547 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongW (hwnd, 0);
1549 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1551 if (!infoPtr && (uMsg != WM_CREATE))
1552 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1557 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1560 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1563 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1565 case TBM_GETCHANNELRECT:
1566 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1568 case TBM_GETLINESIZE:
1569 return infoPtr->lLineSize;
1571 case TBM_GETNUMTICS:
1572 return TRACKBAR_GetNumTics (infoPtr);
1574 case TBM_GETPAGESIZE:
1575 return infoPtr->lPageSize;
1578 return infoPtr->lPos;
1581 return (LRESULT)infoPtr->tics;
1583 case TBM_GETRANGEMAX:
1584 return infoPtr->lRangeMax;
1586 case TBM_GETRANGEMIN:
1587 return infoPtr->lRangeMin;
1590 return infoPtr->lSelMax;
1592 case TBM_GETSELSTART:
1593 return infoPtr->lSelMin;
1595 case TBM_GETTHUMBLENGTH:
1596 return infoPtr->uThumbLen;
1598 case TBM_GETTHUMBRECT:
1599 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1602 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1605 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1607 case TBM_GETTOOLTIPS:
1608 return (LRESULT)infoPtr->hwndToolTip;
1610 case TBM_GETUNICODEFORMAT:
1611 return infoPtr->bUnicode;
1614 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1616 case TBM_SETLINESIZE:
1617 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1619 case TBM_SETPAGESIZE:
1620 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1623 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1626 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1628 case TBM_SETRANGEMAX:
1629 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1631 case TBM_SETRANGEMIN:
1632 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1635 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1638 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1640 case TBM_SETSELSTART:
1641 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1643 case TBM_SETTHUMBLENGTH:
1644 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1647 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1649 case TBM_SETTICFREQ:
1650 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1652 case TBM_SETTIPSIDE:
1653 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1655 case TBM_SETTOOLTIPS:
1656 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1658 case TBM_SETUNICODEFORMAT:
1659 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1662 case WM_CAPTURECHANGED:
1663 return TRACKBAR_CaptureChanged (infoPtr);
1666 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1669 return TRACKBAR_Destroy (infoPtr);
1671 /* case WM_ENABLE: */
1677 return DLGC_WANTARROWS;
1680 return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
1683 return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
1686 return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
1688 case WM_LBUTTONDOWN:
1689 return TRACKBAR_LButtonDown (infoPtr, wParam, MAKEPOINTS(lParam));
1692 return TRACKBAR_LButtonUp (infoPtr, wParam, MAKEPOINTS(lParam));
1695 return TRACKBAR_MouseMove (infoPtr, wParam, MAKEPOINTS(lParam));
1698 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1701 return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
1704 return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
1707 return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
1709 case WM_WININICHANGE:
1710 return TRACKBAR_InitializeThumb (infoPtr);
1713 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1714 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
1715 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1721 void TRACKBAR_Register (void)
1725 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1726 wndClass.style = CS_GLOBALCLASS;
1727 wndClass.lpfnWndProc = (WNDPROC)TRACKBAR_WindowProc;
1728 wndClass.cbClsExtra = 0;
1729 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1730 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1731 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1732 wndClass.lpszClassName = TRACKBAR_CLASSW;
1734 RegisterClassW (&wndClass);
1738 void TRACKBAR_Unregister (void)
1740 UnregisterClassW (TRACKBAR_CLASSW, (HINSTANCE)NULL);