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.
39 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
72 #define TB_REFRESH_TIMER 1
73 #define TB_REFRESH_DELAY 500
75 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
77 /* Used by TRACKBAR_Refresh to find out which parts of the control
78 need to be recalculated */
80 #define TB_THUMBPOSCHANGED 1
81 #define TB_THUMBSIZECHANGED 2
82 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
83 #define TB_SELECTIONCHANGED 4
84 #define TB_DRAG_MODE 8 /* we're dragging the slider */
85 #define TB_AUTO_PAGE_LEFT 16
86 #define TB_AUTO_PAGE_RIGHT 32
87 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
89 /* helper defines for TRACKBAR_DrawTic */
91 #define TIC_SELECTIONMARKMAX 0x80
92 #define TIC_SELECTIONMARKMIN 0x100
93 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
95 static BOOL TRACKBAR_SendNotify (TRACKBAR_INFO *infoPtr, UINT code);
98 notify_customdraw(NMCUSTOMDRAW *pnmcd, int stage)
100 pnmcd->dwDrawStage = stage;
101 return SendMessageW (GetParent(pnmcd->hdr.hwndFrom), WM_NOTIFY,
102 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
105 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
109 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin)
110 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
113 COMCTL32_Free (infoPtr->tics);
114 infoPtr->tics = NULL;
115 infoPtr->uNumTics = 0;
119 if (nrTics != infoPtr->uNumTics) {
120 infoPtr->tics=COMCTL32_ReAlloc (infoPtr->tics,
121 (nrTics+1)*sizeof (DWORD));
122 if (!infoPtr->tics) {
123 infoPtr->uNumTics = 0;
124 TRACKBAR_SendNotify(infoPtr, NM_OUTOFMEMORY);
127 infoPtr->uNumTics = nrTics;
130 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
131 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
132 infoPtr->tics[i] = tic;
135 /* converts from physical (mouse) position to logical position
136 (in range of trackbar) */
139 TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO *infoPtr, int place,
142 double range, width, pos;
144 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
146 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
147 pos = (range*(place - infoPtr->rcChannel.top)) / width;
149 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
150 pos = (range*(place - infoPtr->rcChannel.left)) / width;
152 pos += infoPtr->lRangeMin;
153 if (pos > infoPtr->lRangeMax)
154 pos = infoPtr->lRangeMax;
155 else if (pos < infoPtr->lRangeMin)
156 pos = infoPtr->lRangeMin;
158 TRACE("%.2f\n", pos);
159 return (LONG)(pos + 0.5);
163 /* return: 0> prev, 0 none, >0 next */
165 TRACKBAR_GetAutoPageDirection (TRACKBAR_INFO *infoPtr, POINT clickPoint)
167 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
170 if (dwStyle & TBS_VERT) {
171 pageRect.top = infoPtr->rcChannel.top;
172 pageRect.bottom = infoPtr->rcChannel.bottom;
173 pageRect.left = infoPtr->rcThumb.left;
174 pageRect.right = infoPtr->rcThumb.right;
176 pageRect.top = infoPtr->rcThumb.top;
177 pageRect.bottom = infoPtr->rcThumb.bottom;
178 pageRect.left = infoPtr->rcChannel.left;
179 pageRect.right = infoPtr->rcChannel.right;
183 if (PtInRect(&pageRect, clickPoint))
185 int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
187 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace,
189 return clickPos - infoPtr->lPos;
196 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
198 if (infoPtr->lPos == infoPtr->lRangeMax) return;
200 infoPtr->lPos += infoPtr->lPageSize;
201 if (infoPtr->lPos > infoPtr->lRangeMax)
202 infoPtr->lPos = infoPtr->lRangeMax;
203 TRACKBAR_SendNotify (infoPtr, TB_PAGEUP);
208 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
210 if (infoPtr->lPos == infoPtr->lRangeMin) return;
212 infoPtr->lPos -= infoPtr->lPageSize;
213 if (infoPtr->lPos < infoPtr->lRangeMin)
214 infoPtr->lPos = infoPtr->lRangeMin;
215 TRACKBAR_SendNotify (infoPtr, TB_PAGEDOWN);
219 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
221 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
222 INT cyChannel, offsetthumb, offsetedge;
223 RECT lpRect, *channel = & infoPtr->rcChannel;
225 GetClientRect (infoPtr->hwndSelf, &lpRect);
227 offsetthumb = (int)(infoPtr->uThumbLen/4.5);
228 offsetedge = offsetthumb + 3;
229 cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? (offsetthumb+1)*3 : 4;
230 if (dwStyle & TBS_VERT) {
231 channel->top = lpRect.top + offsetedge;
232 channel->bottom = lpRect.bottom - offsetedge;
233 channel->left = lpRect.left + offsetthumb - cyChannel;
234 if (dwStyle & (TBS_BOTH | TBS_LEFT))
235 channel->left += (lpRect.right-lpRect.left-offsetthumb-cyChannel)/2;
236 channel->right = channel->left + cyChannel;
238 channel->left = lpRect.left + offsetedge;
239 channel->right = lpRect.right - offsetedge;
240 channel->top = lpRect.top + offsetedge;
241 if (dwStyle & (TBS_BOTH | TBS_TOP))
242 channel->top += (lpRect.bottom-lpRect.top-offsetedge-cyChannel)/2;
243 channel->bottom = channel->top + cyChannel;
248 TRACKBAR_CalcThumb (TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
250 int range, width, height, thumbdepth, ticOffset = 5 + 2; /* 5 is length of tic, 2 is extra indent */
251 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
254 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
255 thumbdepth = ((int)(infoPtr->uThumbLen / 4.5)) + 2;
257 if (!range) range = 1;
259 GetClientRect(infoPtr->hwndSelf, &lpRect);
260 if (dwStyle & TBS_VERT)
262 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
264 if (dwStyle & (TBS_BOTH | TBS_LEFT))
265 thumb->left = (lpRect.right - lpRect.left - infoPtr->uThumbLen)/2 + ticOffset;
268 thumb->right = thumb->left + infoPtr->uThumbLen - (ticOffset * 2);
269 thumb->top = infoPtr->rcChannel.top +
270 (height*(lPos - infoPtr->lRangeMin))/range -
272 thumb->bottom = thumb->top + thumbdepth;
276 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
278 thumb->left = infoPtr->rcChannel.left +
279 (width*(lPos - infoPtr->lRangeMin))/range -
281 thumb->right = thumb->left + thumbdepth;
282 if (dwStyle & (TBS_BOTH | TBS_TOP))
283 thumb->top = (lpRect.bottom - lpRect.top - infoPtr->uThumbLen)/2;
286 thumb->bottom = thumb->top + infoPtr->uThumbLen - 20; /* double the bottom padding for the ticks, chosen to resemble native control */
291 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
293 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
297 TRACKBAR_InvalidateAll(TRACKBAR_INFO * infoPtr)
299 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
303 TRACKBAR_InvalidateThumb (TRACKBAR_INFO *infoPtr, LONG thumbPos)
307 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
308 InflateRect(&rcThumb, 1, 1);
309 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
313 TRACKBAR_InvalidateThumbMove (TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
315 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
316 if (newPos != oldPos)
317 TRACKBAR_InvalidateThumb (infoPtr, newPos);
321 TRACKBAR_HasSelection (TRACKBAR_INFO *infoPtr)
323 return infoPtr->lSelMin != infoPtr->lSelMax;
327 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
329 RECT *selection = &infoPtr->rcSelection;
330 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
333 SetRectEmpty (selection);
335 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) {
336 int height = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
337 selection->top = infoPtr->rcChannel.top +
338 (height*infoPtr->lSelMin)/range;
339 selection->bottom = infoPtr->rcChannel.top +
340 (height*infoPtr->lSelMax)/range;
341 selection->left = infoPtr->rcChannel.left + 3;
342 selection->right = infoPtr->rcChannel.right - 3;
344 int width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
345 selection->left = infoPtr->rcChannel.left +
346 (width*infoPtr->lSelMin)/range;
347 selection->right = infoPtr->rcChannel.left +
348 (width*infoPtr->lSelMax)/range;
349 selection->top = infoPtr->rcChannel.top + 3;
350 selection->bottom = infoPtr->rcChannel.bottom - 3;
354 TRACE("selection[left=%ld, top=%ld, right=%ld, bottom=%ld]\n",
355 selection->left, selection->top, selection->right, selection->bottom);
359 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
361 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
362 LONG prevPos = infoPtr->lPos;
364 TRACE("x=%ld, y=%ld, dir=%ld\n", clickPoint.x, clickPoint.y, dir);
366 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
367 TRACKBAR_PageUp(infoPtr);
368 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
369 TRACKBAR_PageDown(infoPtr);
372 infoPtr->flags |= TB_THUMBPOSCHANGED;
373 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
378 /* Trackbar drawing code. I like my spaghetti done milanese. */
381 TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
383 RECT rcChannel = infoPtr->rcChannel;
386 /* make the channel slightly overrun the last tick, to make it look more like the native control, and less "clunky" */
387 if (dwStyle & TBS_VERT) {
388 rcChannel.top -= runOver;
389 rcChannel.bottom += runOver;
391 rcChannel.left -= runOver;
392 rcChannel.right += runOver;
395 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
396 if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
397 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
398 if (TRACKBAR_HasSelection(infoPtr))
399 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
404 TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
406 int x, y, ox, oy, range, side, offset = 5, indent = 0, len = 3;
411 GetClientRect(infoPtr->hwndSelf, &rcTics);
412 if (flags & TBS_VERT) {
413 rcTics.top = infoPtr->rcChannel.top;
414 rcTics.bottom = infoPtr->rcChannel.bottom;
416 rcTics.left = infoPtr->rcChannel.left;
417 rcTics.right = infoPtr->rcChannel.right;
418 rcTics.bottom -= 10; /* value obtained by guesswork and experimentation */
421 if (flags & (TBS_TOP | TBS_LEFT)) {
431 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
433 range = 1; /* to avoid division by zero */
435 if (flags & TIC_SELECTIONMARK) {
436 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
437 } else if (flags & TIC_EDGE) {
441 if (flags & TBS_VERT) {
442 int height = rcTics.bottom - rcTics.top;
443 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
444 x -= (offset + 2) * side;
447 int width = rcTics.right - rcTics.left;
448 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
450 y -= (offset + 2) * side;
455 MoveToEx(hdc, x, y, 0);
456 if (flags & TBS_VERT) x += len * side;
457 else y += len * side;
460 if (flags & TIC_SELECTIONMARK) {
461 if (flags & TBS_VERT) {
466 MoveToEx(hdc, x, y, 0);
467 if (flags & TBS_VERT) {
480 TRACKBAR_DrawTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
482 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
483 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
485 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
486 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags);
490 TRACKBAR_DrawTics (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
492 int i, ticFlags = dwStyle & 0x0f;
493 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
494 HPEN hOldPen, hTicPen;
496 /* create the pen to draw the tics with */
497 hTicPen = CreatePenIndirect(&ticPen);
498 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
500 /* actually draw the tics */
501 for (i=0; i<infoPtr->uNumTics; i++)
502 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
504 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
505 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
507 if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
508 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
509 ticFlags | TIC_SELECTIONMARKMIN);
510 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
511 ticFlags | TIC_SELECTIONMARKMAX);
514 /* clean up the pen, if we created one */
516 SelectObject(hdc, hOldPen);
517 DeleteObject(hTicPen);
522 TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
526 RECT thumb = infoPtr->rcThumb;
532 static INT PointDepth = 4;
533 fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
534 oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
535 SetPolyFillMode (hdc, WINDING);
537 if (dwStyle & TBS_BOTH)
539 points[0].x=thumb.right;
540 points[0].y=thumb.top;
541 points[1].x=thumb.right;
542 points[1].y=thumb.bottom;
543 points[2].x=thumb.left;
544 points[2].y=thumb.bottom;
545 points[3].x=thumb.left;
546 points[3].y=thumb.top;
547 points[4].x=points[0].x;
548 points[4].y=points[0].y;
554 if (dwStyle & TBS_VERT)
556 if (dwStyle & TBS_LEFT)
558 points[0].x=thumb.right;
559 points[0].y=thumb.top;
560 points[1].x=thumb.right;
561 points[1].y=thumb.bottom;
562 points[2].x=thumb.left + PointDepth;
563 points[2].y=thumb.bottom;
564 points[3].x=thumb.left;
565 points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top;
566 points[4].x=thumb.left + PointDepth;
567 points[4].y=thumb.top;
568 points[5].x=points[0].x;
569 points[5].y=points[0].y;
574 points[0].x=thumb.right;
575 points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top;
576 points[1].x=thumb.right - PointDepth;
577 points[1].y=thumb.bottom;
578 points[2].x=thumb.left;
579 points[2].y=thumb.bottom;
580 points[3].x=thumb.left;
581 points[3].y=thumb.top;
582 points[4].x=thumb.right - PointDepth;
583 points[4].y=thumb.top;
584 points[5].x=points[0].x;
585 points[5].y=points[0].y;
590 if (dwStyle & TBS_TOP)
592 points[0].x=(thumb.right - thumb.left) / 2 + thumb.left ;
593 points[0].y=thumb.top;
594 points[1].x=thumb.right;
595 points[1].y=thumb.top + PointDepth;
596 points[2].x=thumb.right;
597 points[2].y=thumb.bottom;
598 points[3].x=thumb.left;
599 points[3].y=thumb.bottom;
600 points[4].x=thumb.left;
601 points[4].y=thumb.top + PointDepth;
602 points[5].x=points[0].x;
603 points[5].y=points[0].y;
608 points[0].x=thumb.right;
609 points[0].y=thumb.top;
610 points[1].x=thumb.right;
611 points[1].y=thumb.bottom - PointDepth;
612 points[2].x=(thumb.right - thumb.left) / 2 + thumb.left ;
613 points[2].y=thumb.bottom;
614 points[3].x=thumb.left;
615 points[3].y=thumb.bottom - PointDepth;
616 points[4].x=thumb.left;
617 points[4].y=thumb.top;
618 points[5].x=points[0].x;
619 points[5].y=points[0].y;
625 /* Draw the thumb now */
626 Polygon (hdc, points, PointCount);
627 oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
628 Polyline(hdc,points, BlackUntil);
629 SelectObject(hdc, GetStockObject(WHITE_PEN));
630 Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
631 SelectObject(hdc, oldpen);
632 SelectObject(hdc, oldbr);
637 TRACKBAR_ActivateToolTip (TRACKBAR_INFO *infoPtr, BOOL fShow)
641 if (!infoPtr->hwndToolTip) return;
643 ZeroMemory(&ti, sizeof(ti));
644 ti.cbSize = sizeof(ti);
645 ti.hwnd = infoPtr->hwndSelf;
647 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
652 TRACKBAR_UpdateToolTip (TRACKBAR_INFO *infoPtr)
654 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
655 WCHAR buf[80], fmt[] = { '%', 'l', 'd', 0 };
661 if (!infoPtr->hwndToolTip) return;
663 ZeroMemory(&ti, sizeof(ti));
664 ti.cbSize = sizeof(ti);
665 ti.hwnd = infoPtr->hwndSelf;
666 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
668 wsprintfW (buf, fmt, infoPtr->lPos);
670 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
672 GetClientRect (infoPtr->hwndSelf, &rcClient);
673 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
674 if (dwStyle & TBS_VERT) {
675 if (infoPtr->fLocation == TBTS_LEFT)
676 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
678 pt.x = rcClient.right + TOOLTIP_OFFSET;
679 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
681 if (infoPtr->fLocation == TBTS_TOP)
682 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
684 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
685 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
687 ClientToScreen(infoPtr->hwndSelf, &pt);
689 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
690 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
695 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
697 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
700 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
704 if (infoPtr->flags & TB_THUMBCHANGED) {
705 TRACKBAR_UpdateThumb (infoPtr);
706 if (infoPtr->flags & TB_THUMBSIZECHANGED)
707 TRACKBAR_CalcChannel (infoPtr);
709 if (infoPtr->flags & TB_SELECTIONCHANGED)
710 TRACKBAR_CalcSelection (infoPtr);
712 if (infoPtr->flags & TB_DRAG_MODE)
713 TRACKBAR_UpdateToolTip (infoPtr);
715 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
717 GetClientRect (infoPtr->hwndSelf, &rcClient);
719 /* try to render offscreen, if we fail, carrry onscreen */
720 hdc = CreateCompatibleDC(hdcDst);
722 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
724 hOldBmp = SelectObject(hdc, hOffScreenBmp);
733 ZeroMemory(&nmcd, sizeof(nmcd));
734 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
735 nmcd.hdr.idFrom = GetWindowLongW (infoPtr->hwndSelf, GWL_ID);
736 nmcd.hdr.code = NM_CUSTOMDRAW;
739 /* start the paint cycle */
741 gcdrf = notify_customdraw(&nmcd, CDDS_PREPAINT);
742 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
744 /* Erase backbround */
745 if (gcdrf == CDRF_DODEFAULT ||
746 notify_customdraw(&nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
747 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
748 if (gcdrf != CDRF_DODEFAULT)
749 notify_customdraw(&nmcd, CDDS_POSTERASE);
753 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
754 nmcd.dwItemSpec = TBCD_CHANNEL;
755 nmcd.uItemState = CDIS_DEFAULT;
756 nmcd.rc = infoPtr->rcChannel;
757 icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
758 } else icdrf = CDRF_DODEFAULT;
759 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
760 TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
761 if (icdrf & CDRF_NOTIFYPOSTPAINT)
762 notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
767 if (!(dwStyle & TBS_NOTICKS)) {
768 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
769 nmcd.dwItemSpec = TBCD_TICS;
770 nmcd.uItemState = CDIS_DEFAULT;
772 icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
773 } else icdrf = CDRF_DODEFAULT;
774 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
775 TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
776 if (icdrf & CDRF_NOTIFYPOSTPAINT)
777 notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
782 if (!(dwStyle & TBS_NOTHUMB)) {
783 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
784 nmcd.dwItemSpec = TBCD_THUMB;
785 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
786 nmcd.rc = infoPtr->rcThumb;
787 icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
788 } else icdrf = CDRF_DODEFAULT;
789 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
790 TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
791 if (icdrf & CDRF_NOTIFYPOSTPAINT)
792 notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
796 /* draw focus rectangle */
797 if (infoPtr->bFocussed) {
798 DrawFocusRect(hdc, &rcClient);
801 /* finish up the painting */
802 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
803 notify_customdraw(&nmcd, CDDS_POSTPAINT);
806 /* cleanup, if we rendered offscreen */
808 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
809 SelectObject(hdc, hOldBmp);
810 DeleteObject(hOffScreenBmp);
817 TRACKBAR_AlignBuddies (TRACKBAR_INFO *infoPtr)
819 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
820 HWND hwndParent = GetParent (infoPtr->hwndSelf);
821 RECT rcSelf, rcBuddy;
824 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
825 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
827 /* align buddy left or above */
828 if (infoPtr->hwndBuddyLA) {
829 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
830 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
832 if (dwStyle & TBS_VERT) {
833 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
834 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
835 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
838 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
839 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
840 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
843 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
844 SWP_NOZORDER | SWP_NOSIZE);
848 /* align buddy right or below */
849 if (infoPtr->hwndBuddyRB) {
850 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
851 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
853 if (dwStyle & TBS_VERT) {
854 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
855 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
860 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
861 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
863 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
864 SWP_NOZORDER | SWP_NOSIZE);
870 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
872 infoPtr->lSelMin = 0;
873 infoPtr->lSelMax = 0;
874 infoPtr->flags |= TB_SELECTIONCHANGED;
876 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
883 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
886 COMCTL32_Free (infoPtr->tics);
887 infoPtr->tics = NULL;
888 infoPtr->uNumTics = 0;
891 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
897 static LRESULT inline
898 TRACKBAR_GetChannelRect (TRACKBAR_INFO *infoPtr, LPRECT lprc)
900 if (lprc == NULL) return 0;
902 lprc->left = infoPtr->rcChannel.left;
903 lprc->right = infoPtr->rcChannel.right;
904 lprc->bottom = infoPtr->rcChannel.bottom;
905 lprc->top = infoPtr->rcChannel.top;
912 TRACKBAR_GetNumTics (TRACKBAR_INFO *infoPtr)
914 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
917 return infoPtr->uNumTics + 2;
921 static int comp_tics(const void *ap, const void *bp)
923 DWORD a = *((DWORD *)ap);
924 DWORD b = *((DWORD *)bp);
926 TRACE("(a=%ld, b=%ld)\n", a, b);
927 if (a < b) return -1;
934 TRACKBAR_GetTic (TRACKBAR_INFO *infoPtr, INT iTic)
936 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
939 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
940 return infoPtr->tics[iTic];
945 TRACKBAR_GetTicPos (TRACKBAR_INFO *infoPtr, INT iTic)
947 LONG range, width, pos, tic;
949 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
952 tic = TRACKBAR_GetTic (infoPtr, iTic);
953 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
954 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
955 pos = infoPtr->rcChannel.left + (width * tic) / range;
962 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
967 /* buddy is left or above */
968 hwndTemp = infoPtr->hwndBuddyLA;
969 infoPtr->hwndBuddyLA = hwndBuddy;
972 /* buddy is right or below */
973 hwndTemp = infoPtr->hwndBuddyRB;
974 infoPtr->hwndBuddyRB = hwndBuddy;
977 TRACKBAR_AlignBuddies (infoPtr);
984 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
986 LONG lTemp = infoPtr->lLineSize;
988 infoPtr->lLineSize = lLineSize;
995 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
997 LONG lTemp = infoPtr->lPageSize;
999 infoPtr->lPageSize = lPageSize;
1005 static LRESULT inline
1006 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1008 LONG oldPos = infoPtr->lPos;
1009 infoPtr->lPos = lPosition;
1011 if (infoPtr->lPos < infoPtr->lRangeMin)
1012 infoPtr->lPos = infoPtr->lRangeMin;
1014 if (infoPtr->lPos > infoPtr->lRangeMax)
1015 infoPtr->lPos = infoPtr->lRangeMax;
1016 infoPtr->flags |= TB_THUMBPOSCHANGED;
1018 if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1024 static LRESULT inline
1025 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
1027 infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
1028 infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
1030 if (infoPtr->lPos < infoPtr->lRangeMin) {
1031 infoPtr->lPos = infoPtr->lRangeMin;
1032 infoPtr->flags |= TB_THUMBPOSCHANGED;
1035 if (infoPtr->lPos > infoPtr->lRangeMax) {
1036 infoPtr->lPos = infoPtr->lRangeMax;
1037 infoPtr->flags |= TB_THUMBPOSCHANGED;
1040 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1041 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1043 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1049 static LRESULT inline
1050 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
1052 infoPtr->lRangeMax = lMax;
1053 if (infoPtr->lPos > infoPtr->lRangeMax) {
1054 infoPtr->lPos = infoPtr->lRangeMax;
1055 infoPtr->flags |= TB_THUMBPOSCHANGED;
1058 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1059 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1061 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1067 static LRESULT inline
1068 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
1070 infoPtr->lRangeMin = lMin;
1071 if (infoPtr->lPos < infoPtr->lRangeMin) {
1072 infoPtr->lPos = infoPtr->lRangeMin;
1073 infoPtr->flags |= TB_THUMBPOSCHANGED;
1076 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1077 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1079 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1085 static LRESULT inline
1086 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1088 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1091 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1092 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1093 infoPtr->flags |= TB_SELECTIONCHANGED;
1095 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1096 infoPtr->lSelMin = infoPtr->lRangeMin;
1097 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1098 infoPtr->lSelMax = infoPtr->lRangeMax;
1100 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1106 static LRESULT inline
1107 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1109 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1112 infoPtr->lSelMax = lEnd;
1113 infoPtr->flags |= TB_SELECTIONCHANGED;
1115 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1116 infoPtr->lSelMax = infoPtr->lRangeMax;
1118 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1124 static LRESULT inline
1125 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1127 if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
1130 infoPtr->lSelMin = lStart;
1131 infoPtr->flags |=TB_SELECTIONCHANGED;
1133 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1134 infoPtr->lSelMin = infoPtr->lRangeMin;
1136 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1142 static LRESULT inline
1143 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1145 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) {
1146 infoPtr->uThumbLen = iLength;
1147 infoPtr->flags |= TB_THUMBSIZECHANGED;
1148 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1155 static LRESULT inline
1156 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1158 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
1161 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1164 TRACE("lPos=%ld\n", lPos);
1166 infoPtr->uNumTics++;
1167 infoPtr->tics=COMCTL32_ReAlloc( infoPtr->tics,
1168 (infoPtr->uNumTics)*sizeof (DWORD));
1169 if (!infoPtr->tics) {
1170 infoPtr->uNumTics = 0;
1171 TRACKBAR_SendNotify(infoPtr, NM_OUTOFMEMORY);
1174 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1176 TRACKBAR_InvalidateAll(infoPtr);
1182 static LRESULT inline
1183 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1185 if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
1186 infoPtr->uTicFreq = wFreq;
1187 TRACKBAR_RecalculateTics (infoPtr);
1188 TRACKBAR_InvalidateAll(infoPtr);
1196 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1198 INT fTemp = infoPtr->fLocation;
1200 infoPtr->fLocation = fLocation;
1206 static LRESULT inline
1207 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1209 infoPtr->hwndToolTip = hwndTT;
1216 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1218 BOOL bTemp = infoPtr->bUnicode;
1220 infoPtr->bUnicode = fUnicode;
1227 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1229 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1232 /* initial thumb length */
1233 GetClientRect(infoPtr->hwndSelf,&rect);
1234 if (dwStyle & TBS_VERT) {
1235 infoPtr->uThumbLen = (rect.right - rect.left - 6);
1237 infoPtr->uThumbLen = (rect.bottom - rect.top);
1240 TRACKBAR_CalcChannel (infoPtr);
1241 TRACKBAR_UpdateThumb (infoPtr);
1242 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1249 TRACKBAR_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
1251 TRACKBAR_INFO *infoPtr;
1252 DWORD oldStyle, newStyle;
1254 infoPtr = (TRACKBAR_INFO *)COMCTL32_Alloc (sizeof(TRACKBAR_INFO));
1255 if (!infoPtr) return -1;
1256 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
1258 /* set default values */
1259 infoPtr->hwndSelf = hwnd;
1260 infoPtr->lRangeMin = 0;
1261 infoPtr->lRangeMax = 100;
1262 infoPtr->lLineSize = 1;
1263 infoPtr->lPageSize = 20;
1264 infoPtr->lSelMin = 0;
1265 infoPtr->lSelMax = 0;
1267 infoPtr->fLocation = -1;
1268 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1269 infoPtr->uTicFreq = 1;
1270 infoPtr->tics = NULL;
1271 infoPtr->hwndNotify= GetParent (hwnd);
1273 TRACKBAR_InitializeThumb (infoPtr);
1275 oldStyle = newStyle = GetWindowLongW (hwnd, GWL_STYLE);
1276 if (oldStyle & TBS_VERT) {
1277 if (! (oldStyle & (TBS_LEFT | TBS_RIGHT | TBS_BOTH)) )
1278 newStyle |= TBS_RIGHT;
1280 if (! (oldStyle & (TBS_TOP | TBS_BOTTOM | TBS_BOTH)) )
1281 newStyle |= TBS_BOTTOM;
1283 if (newStyle != oldStyle)
1284 SetWindowLongW (hwnd, GWL_STYLE, newStyle);
1286 /* Create tooltip control */
1287 if (newStyle & TBS_TOOLTIPS) {
1289 infoPtr->hwndToolTip =
1290 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
1291 CW_USEDEFAULT, CW_USEDEFAULT,
1292 CW_USEDEFAULT, CW_USEDEFAULT,
1295 if (infoPtr->hwndToolTip) {
1297 ZeroMemory (&ti, sizeof(ti));
1298 ti.cbSize = sizeof(ti);
1299 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1302 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1311 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1313 /* delete tooltip control */
1314 if (infoPtr->hwndToolTip)
1315 DestroyWindow (infoPtr->hwndToolTip);
1317 COMCTL32_Free (infoPtr);
1318 SetWindowLongW (infoPtr->hwndSelf, 0, 0);
1324 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
1327 infoPtr->bFocussed = FALSE;
1328 TRACKBAR_InvalidateAll(infoPtr);
1334 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
1336 POINT clickPoint = { pts.x, pts.y };
1338 SetFocus(infoPtr->hwndSelf);
1340 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1341 infoPtr->flags |= TB_DRAG_MODE;
1342 SetCapture (infoPtr->hwndSelf);
1343 TRACKBAR_UpdateToolTip (infoPtr);
1344 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1345 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1347 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1348 if (dir == 0) return 0;
1349 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1350 TRACKBAR_AutoPage (infoPtr, clickPoint);
1351 SetCapture (infoPtr->hwndSelf);
1352 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1360 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
1362 if (infoPtr->flags & TB_DRAG_MODE) {
1363 TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
1364 infoPtr->flags &= ~TB_DRAG_MODE;
1366 TRACKBAR_SendNotify(infoPtr, NM_RELEASEDCAPTURE);
1367 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1368 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1370 if (infoPtr->flags & TB_AUTO_PAGE) {
1371 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1372 infoPtr->flags &= ~TB_AUTO_PAGE;
1374 TRACKBAR_SendNotify(infoPtr, NM_RELEASEDCAPTURE);
1382 TRACKBAR_CaptureChanged (TRACKBAR_INFO *infoPtr)
1384 TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
1390 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1393 TRACKBAR_Refresh(infoPtr, hdc);
1396 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1397 TRACKBAR_Refresh (infoPtr, hdc);
1398 EndPaint (infoPtr->hwndSelf, &ps);
1406 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
1409 infoPtr->bFocussed = TRUE;
1410 TRACKBAR_InvalidateAll(infoPtr);
1417 TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
1419 TRACKBAR_CalcChannel (infoPtr);
1420 TRACKBAR_AlignBuddies (infoPtr);
1427 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, TIMERPROC *tmrpc)
1429 if (infoPtr->flags & TB_AUTO_PAGE) {
1431 if (GetCursorPos(&pt))
1432 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1433 TRACKBAR_AutoPage(infoPtr, pt);
1440 TRACKBAR_SendNotify (TRACKBAR_INFO *infoPtr, UINT code)
1442 BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT;
1444 TRACE("%x\n", code);
1446 return (BOOL) SendMessageW (GetParent (infoPtr->hwndSelf),
1447 bVert ? WM_VSCROLL : WM_HSCROLL,
1448 (WPARAM)code, (LPARAM)infoPtr->hwndSelf);
1453 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
1455 DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
1456 INT clickPlace = (dwStyle & TBS_VERT) ? pts.y : pts.x;
1457 DOUBLE dragPos, oldPos = infoPtr->lPos;
1459 TRACE("(x=%d. y=%d)\n", pts.x, pts.y);
1461 if (infoPtr->flags & TB_AUTO_PAGE) {
1463 POINTSTOPOINT(pt, pts);
1464 TRACKBAR_AutoPage (infoPtr, pt);
1468 if (!(infoPtr->flags & TB_DRAG_MODE)) return TRUE;
1470 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1471 dwStyle & TBS_VERT);
1472 if (dragPos > ((INT)dragPos) + 0.5) dragPos++;
1474 if (dragPos == oldPos) return TRUE;
1476 infoPtr->lPos = dragPos;
1478 infoPtr->flags |= TB_THUMBPOSCHANGED;
1479 TRACKBAR_SendNotify (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1482 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1483 UpdateWindow (infoPtr->hwndSelf);
1490 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1492 BOOL downIsLeft = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_DOWNISLEFT;
1493 LONG pos = infoPtr->lPos;
1495 TRACE("%x\n", nVirtKey);
1499 if (downIsLeft) goto step_right;
1502 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1503 infoPtr->lPos -= infoPtr->lLineSize;
1504 if (infoPtr->lPos < infoPtr->lRangeMin)
1505 infoPtr->lPos = infoPtr->lRangeMin;
1506 TRACKBAR_SendNotify (infoPtr, TB_LINEUP);
1509 if (downIsLeft) goto step_left;
1512 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1513 infoPtr->lPos += infoPtr->lLineSize;
1514 if (infoPtr->lPos > infoPtr->lRangeMax)
1515 infoPtr->lPos = infoPtr->lRangeMax;
1516 TRACKBAR_SendNotify (infoPtr, TB_LINEDOWN);
1519 if (downIsLeft) goto page_left;
1521 TRACKBAR_PageUp(infoPtr);
1524 if (downIsLeft) goto page_right;
1526 TRACKBAR_PageDown(infoPtr);
1529 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1530 infoPtr->lPos = infoPtr->lRangeMin;
1531 TRACKBAR_SendNotify (infoPtr, TB_TOP);
1534 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1535 infoPtr->lPos = infoPtr->lRangeMax;
1536 TRACKBAR_SendNotify (infoPtr, TB_BOTTOM);
1540 if (pos != infoPtr->lPos) {
1541 infoPtr->flags |=TB_THUMBPOSCHANGED;
1542 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1550 TRACKBAR_KeyUp (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
1561 TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
1567 static LRESULT WINAPI
1568 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1570 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongW (hwnd, 0);
1572 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1574 if (!infoPtr && (uMsg != WM_CREATE))
1575 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1580 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1583 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1586 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1588 case TBM_GETCHANNELRECT:
1589 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1591 case TBM_GETLINESIZE:
1592 return infoPtr->lLineSize;
1594 case TBM_GETNUMTICS:
1595 return TRACKBAR_GetNumTics (infoPtr);
1597 case TBM_GETPAGESIZE:
1598 return infoPtr->lPageSize;
1601 return infoPtr->lPos;
1604 return (LRESULT)infoPtr->tics;
1606 case TBM_GETRANGEMAX:
1607 return infoPtr->lRangeMax;
1609 case TBM_GETRANGEMIN:
1610 return infoPtr->lRangeMin;
1613 return infoPtr->lSelMax;
1615 case TBM_GETSELSTART:
1616 return infoPtr->lSelMin;
1618 case TBM_GETTHUMBLENGTH:
1619 return infoPtr->uThumbLen;
1621 case TBM_GETTHUMBRECT:
1622 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1625 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1628 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1630 case TBM_GETTOOLTIPS:
1631 return (LRESULT)infoPtr->hwndToolTip;
1633 case TBM_GETUNICODEFORMAT:
1634 return infoPtr->bUnicode;
1637 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1639 case TBM_SETLINESIZE:
1640 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1642 case TBM_SETPAGESIZE:
1643 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1646 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1649 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1651 case TBM_SETRANGEMAX:
1652 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1654 case TBM_SETRANGEMIN:
1655 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1658 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1661 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1663 case TBM_SETSELSTART:
1664 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1666 case TBM_SETTHUMBLENGTH:
1667 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1670 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1672 case TBM_SETTICFREQ:
1673 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1675 case TBM_SETTIPSIDE:
1676 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1678 case TBM_SETTOOLTIPS:
1679 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1681 case TBM_SETUNICODEFORMAT:
1682 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1685 case WM_CAPTURECHANGED:
1686 return TRACKBAR_CaptureChanged (infoPtr);
1689 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1692 return TRACKBAR_Destroy (infoPtr);
1694 /* case WM_ENABLE: */
1700 return DLGC_WANTARROWS;
1703 return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
1706 return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
1709 return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
1711 case WM_LBUTTONDOWN:
1712 return TRACKBAR_LButtonDown (infoPtr, wParam, MAKEPOINTS(lParam));
1715 return TRACKBAR_LButtonUp (infoPtr, wParam, MAKEPOINTS(lParam));
1718 return TRACKBAR_MouseMove (infoPtr, wParam, MAKEPOINTS(lParam));
1721 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
1724 return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
1727 return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
1730 return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
1732 case WM_WININICHANGE:
1733 return TRACKBAR_InitializeThumb (infoPtr);
1736 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1737 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
1738 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1744 void TRACKBAR_Register (void)
1748 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1749 wndClass.style = CS_GLOBALCLASS;
1750 wndClass.lpfnWndProc = (WNDPROC)TRACKBAR_WindowProc;
1751 wndClass.cbClsExtra = 0;
1752 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1753 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
1754 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1755 wndClass.lpszClassName = TRACKBAR_CLASSW;
1757 RegisterClassW (&wndClass);
1761 void TRACKBAR_Unregister (void)
1763 UnregisterClassW (TRACKBAR_CLASSW, NULL);