webservices: Add a stub implementation of WS_TYPE_ATTRIBUTE_FIELD_MAPPING in the...
[wine.git] / dlls / comctl32 / trackbar.c
blob26f5cdc1dc4ee660fa61869f9e302d5a848a1530
1 /*
2 * Trackbar control
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
22 * NOTE
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.
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <math.h>
39 #include "windef.h"
40 #include "winbase.h"
41 #include "wingdi.h"
42 #include "winuser.h"
43 #include "winnls.h"
44 #include "commctrl.h"
45 #include "uxtheme.h"
46 #include "vssym32.h"
47 #include "wine/debug.h"
49 #include "comctl32.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
53 typedef struct
55 HWND hwndSelf;
56 DWORD dwStyle;
57 LONG lRangeMin;
58 LONG lRangeMax;
59 LONG lLineSize;
60 LONG lPageSize;
61 LONG lSelMin;
62 LONG lSelMax;
63 LONG lPos;
64 UINT uThumbLen;
65 UINT uNumTics;
66 UINT uTicFreq;
67 HWND hwndNotify;
68 HWND hwndToolTip;
69 HWND hwndBuddyLA;
70 HWND hwndBuddyRB;
71 INT fLocation;
72 INT flags;
73 BOOL bUnicode;
74 BOOL bFocussed;
75 RECT rcChannel;
76 RECT rcSelection;
77 RECT rcThumb;
78 LPLONG tics;
79 } TRACKBAR_INFO;
81 #define TB_REFRESH_TIMER 1
82 #define TB_REFRESH_DELAY 500
84 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
86 #define TB_DEFAULTPAGESIZE 20
88 /* Used by TRACKBAR_Refresh to find out which parts of the control
89 need to be recalculated */
91 #define TB_THUMBPOSCHANGED 1
92 #define TB_THUMBSIZECHANGED 2
93 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
94 #define TB_SELECTIONCHANGED 4
95 #define TB_DRAG_MODE 8 /* we're dragging the slider */
96 #define TB_AUTO_PAGE_LEFT 16
97 #define TB_AUTO_PAGE_RIGHT 32
98 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
99 #define TB_THUMB_HOT 64 /* mouse hovers above thumb */
101 /* helper defines for TRACKBAR_DrawTic */
102 #define TIC_EDGE 0x20
103 #define TIC_SELECTIONMARKMAX 0x80
104 #define TIC_SELECTIONMARKMIN 0x100
105 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
107 static const WCHAR themeClass[] = { 'T','r','a','c','k','b','a','r',0 };
109 static inline int
110 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
112 pnmcd->dwDrawStage = stage;
113 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
114 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
117 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
119 LRESULT result;
121 TRACE("(code=%d)\n", code);
123 pnmh->hwndFrom = infoPtr->hwndSelf;
124 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
125 pnmh->code = code;
126 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
128 TRACE(" <= %ld\n", result);
130 return result;
133 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
135 NMHDR nmh;
136 return notify_hdr(infoPtr, code, &nmh);
139 static void notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
141 UINT scroll = infoPtr->dwStyle & TBS_VERT ? WM_VSCROLL : WM_HSCROLL;
143 TRACE("%x\n", code);
145 SendMessageW (infoPtr->hwndNotify, scroll, code, (LPARAM)infoPtr->hwndSelf);
148 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
150 int tic;
151 unsigned nrTics, i;
153 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin) {
154 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
155 /* don't add extra tic if there's no remainder */
156 if (nrTics && ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0))
157 nrTics--;
159 else {
160 Free (infoPtr->tics);
161 infoPtr->tics = NULL;
162 infoPtr->uNumTics = 0;
163 return;
166 if (nrTics != infoPtr->uNumTics) {
167 infoPtr->tics=ReAlloc (infoPtr->tics,
168 (nrTics+1)*sizeof (DWORD));
169 if (!infoPtr->tics) {
170 infoPtr->uNumTics = 0;
171 notify(infoPtr, NM_OUTOFMEMORY);
172 return;
174 infoPtr->uNumTics = nrTics;
177 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
178 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
179 infoPtr->tics[i] = tic;
182 /* converts from physical (mouse) position to logical position
183 (in range of trackbar) */
185 static inline LONG
186 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place)
188 double range, width, pos, offsetthumb;
190 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
191 if (infoPtr->dwStyle & TBS_VERT) {
192 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
193 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
194 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
195 } else {
196 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
197 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
198 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
200 pos += infoPtr->lRangeMin;
201 if (pos > infoPtr->lRangeMax)
202 pos = infoPtr->lRangeMax;
203 else if (pos < infoPtr->lRangeMin)
204 pos = infoPtr->lRangeMin;
206 TRACE("%.2f\n", pos);
207 return (LONG)floor(pos + 0.5);
211 /* return: 0> prev, 0 none, >0 next */
212 static LONG
213 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
215 RECT pageRect;
217 if (infoPtr->dwStyle & TBS_VERT) {
218 pageRect.top = infoPtr->rcChannel.top;
219 pageRect.bottom = infoPtr->rcChannel.bottom;
220 pageRect.left = infoPtr->rcThumb.left;
221 pageRect.right = infoPtr->rcThumb.right;
222 } else {
223 pageRect.top = infoPtr->rcThumb.top;
224 pageRect.bottom = infoPtr->rcThumb.bottom;
225 pageRect.left = infoPtr->rcChannel.left;
226 pageRect.right = infoPtr->rcChannel.right;
230 if (PtInRect(&pageRect, clickPoint))
232 int clickPlace = (infoPtr->dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
234 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace);
236 return clickPos - infoPtr->lPos;
239 return 0;
242 static inline void
243 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
245 if (infoPtr->lPos == infoPtr->lRangeMax) return;
247 infoPtr->lPos += infoPtr->lPageSize;
248 if (infoPtr->lPos > infoPtr->lRangeMax)
249 infoPtr->lPos = infoPtr->lRangeMax;
250 notify_with_scroll (infoPtr, TB_PAGEDOWN);
254 static inline void
255 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
257 if (infoPtr->lPos == infoPtr->lRangeMin) return;
259 infoPtr->lPos -= infoPtr->lPageSize;
260 if (infoPtr->lPos < infoPtr->lRangeMin)
261 infoPtr->lPos = infoPtr->lRangeMin;
262 notify_with_scroll (infoPtr, TB_PAGEUP);
265 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
267 if (infoPtr->lPos == infoPtr->lRangeMin) return;
268 infoPtr->lPos -= infoPtr->lLineSize;
269 if (infoPtr->lPos < infoPtr->lRangeMin)
270 infoPtr->lPos = infoPtr->lRangeMin;
271 notify_with_scroll (infoPtr, TB_LINEUP);
274 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
276 if (infoPtr->lPos == infoPtr->lRangeMax) return;
277 infoPtr->lPos += infoPtr->lLineSize;
278 if (infoPtr->lPos > infoPtr->lRangeMax)
279 infoPtr->lPos = infoPtr->lRangeMax;
280 notify_with_scroll (infoPtr, TB_LINEDOWN);
283 static void
284 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
286 INT cyChannel, offsetthumb, offsetedge;
287 RECT lpRect, *channel = & infoPtr->rcChannel;
289 GetClientRect (infoPtr->hwndSelf, &lpRect);
291 offsetthumb = infoPtr->uThumbLen / 4;
292 offsetedge = offsetthumb + 3;
293 cyChannel = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
294 if (infoPtr->dwStyle & TBS_VERT) {
295 channel->top = lpRect.top + offsetedge;
296 channel->bottom = lpRect.bottom - offsetedge;
297 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
298 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
299 else
300 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
301 if (infoPtr->dwStyle & TBS_BOTH) {
302 if (infoPtr->dwStyle & TBS_NOTICKS)
303 channel->left += 1;
304 else
305 channel->left += 9;
307 else if (infoPtr->dwStyle & TBS_TOP) {
308 if (infoPtr->dwStyle & TBS_NOTICKS)
309 channel->left += 2;
310 else
311 channel->left += 10;
313 channel->right = channel->left + cyChannel;
314 } else {
315 channel->left = lpRect.left + offsetedge;
316 channel->right = lpRect.right - offsetedge;
317 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
318 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
319 else
320 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
321 if (infoPtr->dwStyle & TBS_BOTH) {
322 if (infoPtr->dwStyle & TBS_NOTICKS)
323 channel->top += 1;
324 else
325 channel->top += 9;
327 else if (infoPtr->dwStyle & TBS_TOP) {
328 if (infoPtr->dwStyle & TBS_NOTICKS)
329 channel->top += 2;
330 else
331 channel->top += 10;
333 channel->bottom = channel->top + cyChannel;
337 static void
338 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
340 int range, width, height, thumbwidth;
341 RECT lpRect;
343 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
344 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
346 if (!range) range = 1;
348 GetClientRect(infoPtr->hwndSelf, &lpRect);
349 if (infoPtr->dwStyle & TBS_VERT)
351 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
353 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_LEFT)) && !(infoPtr->dwStyle & TBS_NOTICKS))
354 thumb->left = 10;
355 else
356 thumb->left = 2;
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;
362 else
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 ((infoPtr->dwStyle & (TBS_BOTH | TBS_TOP)) && !(infoPtr->dwStyle & TBS_NOTICKS))
370 thumb->top = 10;
371 else
372 thumb->top = 2;
373 thumb->bottom = thumb->top + infoPtr->uThumbLen;
377 static inline void
378 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
380 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
383 static inline void
384 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
386 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
389 static void
390 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
392 RECT rcThumb;
394 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
395 InflateRect(&rcThumb, 1, 1);
396 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
399 static inline void
400 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
402 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
403 if (newPos != oldPos)
404 TRACKBAR_InvalidateThumb (infoPtr, newPos);
407 static inline BOOL
408 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
410 return infoPtr->lSelMin != infoPtr->lSelMax;
413 static void
414 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
416 RECT *selection = &infoPtr->rcSelection;
417 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
418 int offsetthumb, height, width;
420 if (range <= 0) {
421 SetRectEmpty (selection);
422 } else {
423 if (infoPtr->dwStyle & 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;
432 } else {
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[%s]\n", wine_dbgstr_rect(selection));
447 static BOOL
448 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
450 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
451 LONG prevPos = infoPtr->lPos;
453 TRACE("x=%d, y=%d, dir=%d\n", clickPoint.x, clickPoint.y, dir);
455 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
456 TRACKBAR_PageDown(infoPtr);
457 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
458 TRACKBAR_PageUp(infoPtr);
459 else return FALSE;
461 TRACKBAR_UpdateThumb (infoPtr);
462 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
464 return TRUE;
467 /* Trackbar drawing code. I like my spaghetti done milanese. */
469 static void
470 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc)
472 RECT rcChannel = infoPtr->rcChannel;
473 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
475 if (theme)
477 DrawThemeBackground (theme, hdc,
478 (infoPtr->dwStyle & TBS_VERT) ?
479 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
481 else
483 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
484 if (infoPtr->dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
485 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
486 if (TRACKBAR_HasSelection(infoPtr))
487 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
492 static void
493 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
495 int x, y, ox, oy, range, side, indent = 0, len = 3;
496 int offsetthumb;
497 RECT rcTics;
499 if (flags & TBS_VERT) {
500 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
501 SetRect(&rcTics, infoPtr->rcThumb.left - 2, infoPtr->rcChannel.top + offsetthumb,
502 infoPtr->rcThumb.right + 2, infoPtr->rcChannel.bottom - offsetthumb - 1);
503 } else {
504 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
505 SetRect(&rcTics, infoPtr->rcChannel.left + offsetthumb, infoPtr->rcThumb.top - 2,
506 infoPtr->rcChannel.right - offsetthumb - 1, infoPtr->rcThumb.bottom + 2);
509 if (flags & (TBS_TOP | TBS_LEFT)) {
510 x = rcTics.left;
511 y = rcTics.top;
512 side = -1;
513 } else {
514 x = rcTics.right;
515 y = rcTics.bottom;
516 side = 1;
519 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
520 if (range <= 0)
521 range = 1; /* to avoid division by zero */
523 if (flags & TIC_SELECTIONMARK) {
524 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
525 } else if (flags & TIC_EDGE) {
526 len++;
529 if (flags & TBS_VERT) {
530 int height = rcTics.bottom - rcTics.top;
531 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
532 } else {
533 int width = rcTics.right - rcTics.left;
534 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
537 ox = x;
538 oy = y;
539 MoveToEx(hdc, x, y, 0);
540 if (flags & TBS_VERT) x += len * side;
541 else y += len * side;
542 LineTo(hdc, x, y);
544 if (flags & TIC_SELECTIONMARK) {
545 if (flags & TBS_VERT) {
546 x -= side;
547 } else {
548 y -= side;
550 MoveToEx(hdc, x, y, 0);
551 if (flags & TBS_VERT) {
552 y += 2 * indent;
553 } else {
554 x += 2 * indent;
557 LineTo(hdc, x, y);
558 LineTo(hdc, ox, oy);
563 static inline void
564 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
566 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
567 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
569 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
570 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
573 static void
574 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc)
576 unsigned int i;
577 int ticFlags = infoPtr->dwStyle & 0x0f;
578 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
579 HPEN hOldPen, hTicPen;
580 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
582 if (theme)
584 int part = (infoPtr->dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
585 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
587 /* create the pen to draw the tics with */
588 hTicPen = CreatePenIndirect(&ticPen);
589 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
591 /* actually draw the tics */
592 for (i=0; i<infoPtr->uNumTics; i++)
593 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
595 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
596 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
598 if ((infoPtr->dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
599 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
600 ticFlags | TIC_SELECTIONMARKMIN);
601 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
602 ticFlags | TIC_SELECTIONMARKMAX);
605 /* clean up the pen, if we created one */
606 if (hTicPen) {
607 SelectObject(hdc, hOldPen);
608 DeleteObject(hTicPen);
612 static int
613 TRACKBAR_FillThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, HBRUSH hbrush)
615 const RECT *thumb = &infoPtr->rcThumb;
616 POINT points[6];
617 int PointDepth;
618 HBRUSH oldbr;
620 if (infoPtr->dwStyle & TBS_BOTH)
622 FillRect(hdc, thumb, hbrush);
623 return 0;
626 if (infoPtr->dwStyle & TBS_VERT)
628 PointDepth = (thumb->bottom - thumb->top) / 2;
629 if (infoPtr->dwStyle & TBS_LEFT)
631 points[0].x = thumb->right-1;
632 points[0].y = thumb->top;
633 points[1].x = thumb->right-1;
634 points[1].y = thumb->bottom-1;
635 points[2].x = thumb->left + PointDepth;
636 points[2].y = thumb->bottom-1;
637 points[3].x = thumb->left;
638 points[3].y = thumb->top + PointDepth;
639 points[4].x = thumb->left + PointDepth;
640 points[4].y = thumb->top;
641 points[5].x = points[0].x;
642 points[5].y = points[0].y;
644 else
646 points[0].x = thumb->right;
647 points[0].y = thumb->top + PointDepth;
648 points[1].x = thumb->right - PointDepth;
649 points[1].y = thumb->bottom-1;
650 points[2].x = thumb->left;
651 points[2].y = thumb->bottom-1;
652 points[3].x = thumb->left;
653 points[3].y = thumb->top;
654 points[4].x = thumb->right - PointDepth;
655 points[4].y = thumb->top;
656 points[5].x = points[0].x;
657 points[5].y = points[0].y;
660 else
662 PointDepth = (thumb->right - thumb->left) / 2;
663 if (infoPtr->dwStyle & TBS_TOP)
665 points[0].x = thumb->left + PointDepth;
666 points[0].y = thumb->top+1;
667 points[1].x = thumb->right-1;
668 points[1].y = thumb->top + PointDepth + 1;
669 points[2].x = thumb->right-1;
670 points[2].y = thumb->bottom-1;
671 points[3].x = thumb->left;
672 points[3].y = thumb->bottom-1;
673 points[4].x = thumb->left;
674 points[4].y = thumb->top + PointDepth + 1;
675 points[5].x = points[0].x;
676 points[5].y = points[0].y;
678 else
680 points[0].x = thumb->right-1;
681 points[0].y = thumb->top;
682 points[1].x = thumb->right-1;
683 points[1].y = thumb->bottom - PointDepth - 1;
684 points[2].x = thumb->left + PointDepth;
685 points[2].y = thumb->bottom-1;
686 points[3].x = thumb->left;
687 points[3].y = thumb->bottom - PointDepth - 1;
688 points[4].x = thumb->left;
689 points[4].y = thumb->top;
690 points[5].x = points[0].x;
691 points[5].y = points[0].y;
695 oldbr = SelectObject(hdc, hbrush);
696 SetPolyFillMode(hdc, WINDING);
697 Polygon(hdc, points, sizeof(points) / sizeof(points[0]));
698 SelectObject(hdc, oldbr);
700 return PointDepth;
703 static void
704 TRACKBAR_DrawThumb (TRACKBAR_INFO *infoPtr, HDC hdc)
706 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
707 int PointDepth;
708 HBRUSH brush;
710 if (theme)
712 int partId;
713 int stateId;
714 if (infoPtr->dwStyle & TBS_BOTH)
715 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
716 else if (infoPtr->dwStyle & TBS_LEFT)
717 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
718 else
719 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
721 if (infoPtr->dwStyle & WS_DISABLED)
722 stateId = TUS_DISABLED;
723 else if (infoPtr->flags & TB_DRAG_MODE)
724 stateId = TUS_PRESSED;
725 else if (infoPtr->flags & TB_THUMB_HOT)
726 stateId = TUS_HOT;
727 else
728 stateId = TUS_NORMAL;
730 DrawThemeBackground (theme, hdc, partId, stateId, &infoPtr->rcThumb, NULL);
732 return;
735 if (infoPtr->dwStyle & WS_DISABLED || infoPtr->flags & TB_DRAG_MODE)
737 if (comctl32_color.clr3dHilight == comctl32_color.clrWindow)
738 brush = COMCTL32_hPattern55AABrush;
739 else
740 brush = GetSysColorBrush(COLOR_SCROLLBAR);
742 SetTextColor(hdc, comctl32_color.clr3dFace);
743 SetBkColor(hdc, comctl32_color.clr3dHilight);
745 else
746 brush = GetSysColorBrush(COLOR_BTNFACE);
748 PointDepth = TRACKBAR_FillThumb(infoPtr, hdc, brush);
750 if (infoPtr->dwStyle & TBS_BOTH)
752 DrawEdge(hdc, &infoPtr->rcThumb, EDGE_RAISED, BF_RECT | BF_SOFT);
753 return;
755 else
757 RECT thumb = infoPtr->rcThumb;
759 if (infoPtr->dwStyle & TBS_VERT)
761 if (infoPtr->dwStyle & TBS_LEFT)
763 /* rectangular part */
764 thumb.left += PointDepth;
765 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_RIGHT | BF_BOTTOM | BF_SOFT);
767 /* light edge */
768 thumb.left -= PointDepth;
769 thumb.right = thumb.left + PointDepth;
770 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
771 thumb.top = infoPtr->rcThumb.top;
772 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
774 /* shadowed edge */
775 thumb.top += PointDepth;
776 thumb.bottom += PointDepth;
777 DrawEdge(hdc, &thumb, EDGE_SUNKEN, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
778 return;
780 else
782 /* rectangular part */
783 thumb.right -= PointDepth;
784 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_LEFT | BF_BOTTOM | BF_SOFT);
786 /* light edge */
787 thumb.left = thumb.right;
788 thumb.right += PointDepth + 1;
789 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
790 thumb.top = infoPtr->rcThumb.top;
791 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
793 /* shadowed edge */
794 thumb.top += PointDepth;
795 thumb.bottom += PointDepth;
796 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
799 else
801 if (infoPtr->dwStyle & TBS_TOP)
803 /* rectangular part */
804 thumb.top += PointDepth;
805 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_BOTTOM | BF_RIGHT | BF_SOFT);
807 /* light edge */
808 thumb.left = infoPtr->rcThumb.left;
809 thumb.right = thumb.left + PointDepth;
810 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
811 thumb.top -= PointDepth;
812 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
814 /* shadowed edge */
815 thumb.left += PointDepth;
816 thumb.right += PointDepth;
817 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMRIGHT | BF_SOFT);
819 else
821 /* rectangular part */
822 thumb.bottom -= PointDepth;
823 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT);
825 /* light edge */
826 thumb.left = infoPtr->rcThumb.left;
827 thumb.right = thumb.left + PointDepth;
828 thumb.top = infoPtr->rcThumb.bottom - PointDepth - 1;
829 thumb.bottom += PointDepth;
830 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
832 /* shadowed edge */
833 thumb.left += PointDepth;
834 thumb.right += PointDepth;
835 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
842 static inline void
843 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
845 TTTOOLINFOW ti;
847 if (!infoPtr->hwndToolTip) return;
849 ZeroMemory(&ti, sizeof(ti));
850 ti.cbSize = sizeof(ti);
851 ti.hwnd = infoPtr->hwndSelf;
853 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
857 static void
858 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
860 WCHAR buf[80];
861 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
862 TTTOOLINFOW ti;
863 POINT pt;
864 RECT rcClient;
865 LRESULT size;
867 if (!infoPtr->hwndToolTip) return;
869 ZeroMemory(&ti, sizeof(ti));
870 ti.cbSize = sizeof(ti);
871 ti.hwnd = infoPtr->hwndSelf;
872 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
874 wsprintfW (buf, fmt, infoPtr->lPos);
875 ti.lpszText = buf;
876 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
878 GetClientRect (infoPtr->hwndSelf, &rcClient);
879 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
880 if (infoPtr->dwStyle & TBS_VERT) {
881 if (infoPtr->fLocation == TBTS_LEFT)
882 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
883 else
884 pt.x = rcClient.right + TOOLTIP_OFFSET;
885 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
886 } else {
887 if (infoPtr->fLocation == TBTS_TOP)
888 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
889 else
890 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
891 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
893 ClientToScreen(infoPtr->hwndSelf, &pt);
895 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
896 0, MAKELPARAM(pt.x, pt.y));
900 static void
901 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
903 RECT rcClient;
904 HDC hdc;
905 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
906 NMCUSTOMDRAW nmcd;
907 int gcdrf, icdrf;
909 if (infoPtr->flags & TB_THUMBCHANGED) {
910 TRACKBAR_UpdateThumb (infoPtr);
911 if (infoPtr->flags & TB_THUMBSIZECHANGED)
912 TRACKBAR_CalcChannel (infoPtr);
914 if (infoPtr->flags & TB_SELECTIONCHANGED)
915 TRACKBAR_CalcSelection (infoPtr);
917 if (infoPtr->flags & TB_DRAG_MODE)
918 TRACKBAR_UpdateToolTip (infoPtr);
920 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
922 GetClientRect (infoPtr->hwndSelf, &rcClient);
924 /* try to render offscreen, if we fail, carrry onscreen */
925 hdc = CreateCompatibleDC(hdcDst);
926 if (hdc) {
927 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
928 if (hOffScreenBmp) {
929 hOldBmp = SelectObject(hdc, hOffScreenBmp);
930 } else {
931 DeleteObject(hdc);
932 hdc = hdcDst;
934 } else {
935 hdc = hdcDst;
938 ZeroMemory(&nmcd, sizeof(nmcd));
939 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
940 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
941 nmcd.hdr.code = NM_CUSTOMDRAW;
942 nmcd.hdc = hdc;
944 /* start the paint cycle */
945 nmcd.rc = rcClient;
946 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
947 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
949 /* Erase background */
950 if (gcdrf == CDRF_DODEFAULT ||
951 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
952 if (GetWindowTheme (infoPtr->hwndSelf)) {
953 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
955 else {
956 HBRUSH brush = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLORSTATIC,
957 (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
958 FillRect (hdc, &rcClient, brush ? brush : GetSysColorBrush(COLOR_BTNFACE));
960 if (gcdrf != CDRF_DODEFAULT)
961 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
964 /* draw channel */
965 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
966 nmcd.dwItemSpec = TBCD_CHANNEL;
967 nmcd.uItemState = CDIS_DEFAULT;
968 nmcd.rc = infoPtr->rcChannel;
969 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
970 } else icdrf = CDRF_DODEFAULT;
971 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
972 TRACKBAR_DrawChannel (infoPtr, hdc);
973 if (icdrf & CDRF_NOTIFYPOSTPAINT)
974 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
978 /* draw tics */
979 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
980 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
981 nmcd.dwItemSpec = TBCD_TICS;
982 nmcd.uItemState = CDIS_DEFAULT;
983 nmcd.rc = rcClient;
984 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
985 } else icdrf = CDRF_DODEFAULT;
986 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
987 TRACKBAR_DrawTics (infoPtr, hdc);
988 if (icdrf & CDRF_NOTIFYPOSTPAINT)
989 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
993 /* draw thumb */
994 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
995 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
996 nmcd.dwItemSpec = TBCD_THUMB;
997 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
998 nmcd.rc = infoPtr->rcThumb;
999 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
1000 } else icdrf = CDRF_DODEFAULT;
1001 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
1002 TRACKBAR_DrawThumb(infoPtr, hdc);
1003 if (icdrf & CDRF_NOTIFYPOSTPAINT)
1004 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
1008 /* draw focus rectangle */
1009 if (infoPtr->bFocussed) {
1010 DrawFocusRect(hdc, &rcClient);
1013 /* finish up the painting */
1014 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
1015 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
1017 cleanup:
1018 /* cleanup, if we rendered offscreen */
1019 if (hdc != hdcDst) {
1020 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
1021 SelectObject(hdc, hOldBmp);
1022 DeleteObject(hOffScreenBmp);
1023 DeleteObject(hdc);
1028 static void
1029 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
1031 HWND hwndParent = GetParent (infoPtr->hwndSelf);
1032 RECT rcSelf, rcBuddy;
1033 INT x, y;
1035 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
1036 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
1038 /* align buddy left or above */
1039 if (infoPtr->hwndBuddyLA) {
1040 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
1041 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1043 if (infoPtr->dwStyle & TBS_VERT) {
1044 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1045 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1046 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
1048 else {
1049 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
1050 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1051 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1054 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
1055 SWP_NOZORDER | SWP_NOSIZE);
1059 /* align buddy right or below */
1060 if (infoPtr->hwndBuddyRB) {
1061 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
1062 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1064 if (infoPtr->dwStyle & TBS_VERT) {
1065 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1066 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1067 y = rcSelf.bottom;
1069 else {
1070 x = rcSelf.right;
1071 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1072 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1074 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
1075 SWP_NOZORDER | SWP_NOSIZE);
1080 static LRESULT
1081 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1083 infoPtr->lSelMin = 0;
1084 infoPtr->lSelMax = 0;
1085 infoPtr->flags |= TB_SELECTIONCHANGED;
1087 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1089 return 0;
1093 static LRESULT
1094 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1096 if (infoPtr->tics) {
1097 Free (infoPtr->tics);
1098 infoPtr->tics = NULL;
1099 infoPtr->uNumTics = 0;
1102 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1104 return 0;
1108 static inline LRESULT
1109 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1111 if (lprc == NULL) return 0;
1113 lprc->left = infoPtr->rcChannel.left;
1114 lprc->right = infoPtr->rcChannel.right;
1115 lprc->bottom = infoPtr->rcChannel.bottom;
1116 lprc->top = infoPtr->rcChannel.top;
1118 return 0;
1122 static inline LONG
1123 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1125 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1127 return infoPtr->uNumTics + 2;
1131 static int comp_tics (const void *ap, const void *bp)
1133 const DWORD a = *(const DWORD *)ap;
1134 const DWORD b = *(const DWORD *)bp;
1136 TRACE("(a=%d, b=%d)\n", a, b);
1137 if (a < b) return -1;
1138 if (a > b) return 1;
1139 return 0;
1143 static inline LONG
1144 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1146 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1147 return -1;
1149 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1150 return infoPtr->tics[iTic];
1154 static inline LONG
1155 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1157 LONG range, width, pos, tic;
1158 int offsetthumb;
1160 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1161 return -1;
1163 tic = TRACKBAR_GetTic (infoPtr, iTic);
1164 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1165 if (range <= 0) range = 1;
1166 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1167 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1168 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1170 return pos;
1174 static HWND
1175 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1177 HWND hwndTemp;
1179 if (fLocation) {
1180 /* buddy is left or above */
1181 hwndTemp = infoPtr->hwndBuddyLA;
1182 infoPtr->hwndBuddyLA = hwndBuddy;
1184 else {
1185 /* buddy is right or below */
1186 hwndTemp = infoPtr->hwndBuddyRB;
1187 infoPtr->hwndBuddyRB = hwndBuddy;
1190 TRACKBAR_AlignBuddies (infoPtr);
1192 return hwndTemp;
1196 static inline LONG
1197 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1199 LONG lTemp = infoPtr->lLineSize;
1201 infoPtr->lLineSize = lLineSize;
1203 return lTemp;
1207 static inline LONG
1208 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1210 LONG lTemp = infoPtr->lPageSize;
1212 if (lPageSize != -1)
1213 infoPtr->lPageSize = lPageSize;
1214 else
1215 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1217 return lTemp;
1221 static inline LRESULT
1222 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1224 LONG oldPos = infoPtr->lPos;
1225 infoPtr->lPos = lPosition;
1227 if (infoPtr->lPos < infoPtr->lRangeMin)
1228 infoPtr->lPos = infoPtr->lRangeMin;
1230 if (infoPtr->lPos > infoPtr->lRangeMax)
1231 infoPtr->lPos = infoPtr->lRangeMax;
1233 if (fPosition && oldPos != lPosition)
1235 TRACKBAR_UpdateThumb(infoPtr);
1236 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1239 return 0;
1243 static inline LRESULT
1244 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
1246 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1247 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1249 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1250 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1252 /* clip position to new min/max limit */
1253 if (infoPtr->lPos < infoPtr->lRangeMin)
1254 infoPtr->lPos = infoPtr->lRangeMin;
1256 if (infoPtr->lPos > infoPtr->lRangeMax)
1257 infoPtr->lPos = infoPtr->lRangeMax;
1259 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1260 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1262 if (changed) {
1263 if (infoPtr->dwStyle & TBS_AUTOTICKS)
1264 TRACKBAR_RecalculateTics (infoPtr);
1265 infoPtr->flags |= TB_THUMBPOSCHANGED;
1268 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1270 return 0;
1274 static inline LRESULT
1275 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1277 BOOL changed = infoPtr->lRangeMax != lMax;
1279 infoPtr->lRangeMax = lMax;
1280 if (infoPtr->lPos > infoPtr->lRangeMax) {
1281 infoPtr->lPos = infoPtr->lRangeMax;
1282 infoPtr->flags |= TB_THUMBPOSCHANGED;
1285 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1286 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1288 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1289 TRACKBAR_RecalculateTics (infoPtr);
1291 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1293 return 0;
1297 static inline LRESULT
1298 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1300 BOOL changed = infoPtr->lRangeMin != lMin;
1302 infoPtr->lRangeMin = lMin;
1303 if (infoPtr->lPos < infoPtr->lRangeMin) {
1304 infoPtr->lPos = infoPtr->lRangeMin;
1305 infoPtr->flags |= TB_THUMBPOSCHANGED;
1308 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1309 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1311 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1312 TRACKBAR_RecalculateTics (infoPtr);
1314 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1316 return 0;
1320 static inline LRESULT
1321 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1323 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1324 infoPtr->lSelMin = 0;
1325 infoPtr->lSelMax = 0;
1326 return 0;
1329 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1330 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1331 infoPtr->flags |= TB_SELECTIONCHANGED;
1333 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1334 infoPtr->lSelMin = infoPtr->lRangeMin;
1335 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1336 infoPtr->lSelMax = infoPtr->lRangeMax;
1338 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1340 return 0;
1344 static inline LRESULT
1345 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1347 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1348 infoPtr->lSelMax = 0;
1349 return 0;
1352 infoPtr->lSelMax = lEnd;
1353 infoPtr->flags |= TB_SELECTIONCHANGED;
1355 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1356 infoPtr->lSelMax = infoPtr->lRangeMax;
1358 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1360 return 0;
1364 static inline LRESULT
1365 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1367 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1368 infoPtr->lSelMin = 0;
1369 return 0;
1372 infoPtr->lSelMin = lStart;
1373 infoPtr->flags |=TB_SELECTIONCHANGED;
1375 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1376 infoPtr->lSelMin = infoPtr->lRangeMin;
1378 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1380 return 0;
1384 static inline LRESULT
1385 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1387 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1388 /* We're not supposed to check if it's really changed or not,
1389 just repaint in any case. */
1390 infoPtr->uThumbLen = iLength;
1391 infoPtr->flags |= TB_THUMBSIZECHANGED;
1392 TRACKBAR_InvalidateAll(infoPtr);
1395 return 0;
1399 static inline LRESULT
1400 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1402 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1403 return FALSE;
1405 TRACE("lPos=%d\n", lPos);
1407 infoPtr->uNumTics++;
1408 infoPtr->tics=ReAlloc( infoPtr->tics,
1409 (infoPtr->uNumTics)*sizeof (DWORD));
1410 if (!infoPtr->tics) {
1411 infoPtr->uNumTics = 0;
1412 notify(infoPtr, NM_OUTOFMEMORY);
1413 return FALSE;
1415 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1417 TRACKBAR_InvalidateAll(infoPtr);
1419 return TRUE;
1423 static inline LRESULT
1424 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1426 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1427 infoPtr->uTicFreq = wFreq;
1428 TRACKBAR_RecalculateTics (infoPtr);
1429 TRACKBAR_InvalidateAll(infoPtr);
1432 return 0;
1436 static inline INT
1437 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1439 INT fTemp = infoPtr->fLocation;
1441 infoPtr->fLocation = fLocation;
1443 return fTemp;
1447 static inline LRESULT
1448 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1450 infoPtr->hwndToolTip = hwndTT;
1452 return 0;
1456 static inline BOOL
1457 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1459 BOOL bTemp = infoPtr->bUnicode;
1461 infoPtr->bUnicode = fUnicode;
1463 return bTemp;
1467 static LRESULT
1468 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1470 RECT rect;
1471 int clientWidth, clientMetric;
1473 /* initial thumb length */
1474 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1475 GetClientRect(infoPtr->hwndSelf,&rect);
1476 if (infoPtr->dwStyle & TBS_VERT) {
1477 clientWidth = rect.right - rect.left;
1478 } else {
1479 clientWidth = rect.bottom - rect.top;
1481 if (clientWidth >= clientMetric)
1482 infoPtr->uThumbLen = clientMetric;
1483 else
1484 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1486 TRACKBAR_CalcChannel (infoPtr);
1487 TRACKBAR_UpdateThumb (infoPtr);
1488 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1490 return 0;
1494 static LRESULT
1495 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1497 TRACKBAR_INFO *infoPtr;
1499 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1500 if (!infoPtr) return -1;
1501 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1503 /* set default values */
1504 infoPtr->hwndSelf = hwnd;
1505 infoPtr->dwStyle = lpcs->style;
1506 infoPtr->lRangeMin = 0;
1507 infoPtr->lRangeMax = 100;
1508 infoPtr->lLineSize = 1;
1509 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1510 infoPtr->lSelMin = 0;
1511 infoPtr->lSelMax = 0;
1512 infoPtr->lPos = 0;
1513 infoPtr->fLocation = TBTS_TOP;
1514 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1515 infoPtr->uTicFreq = 1;
1516 infoPtr->tics = NULL;
1517 infoPtr->hwndNotify= lpcs->hwndParent;
1519 TRACKBAR_InitializeThumb (infoPtr);
1521 /* Create tooltip control */
1522 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1524 infoPtr->hwndToolTip =
1525 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1526 CW_USEDEFAULT, CW_USEDEFAULT,
1527 CW_USEDEFAULT, CW_USEDEFAULT,
1528 hwnd, 0, 0, 0);
1530 if (infoPtr->hwndToolTip) {
1531 TTTOOLINFOW ti;
1532 WCHAR wEmpty = 0;
1533 ZeroMemory (&ti, sizeof(ti));
1534 ti.cbSize = sizeof(ti);
1535 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1536 ti.hwnd = hwnd;
1537 ti.lpszText = &wEmpty;
1539 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1543 OpenThemeData (hwnd, themeClass);
1545 return 0;
1549 static LRESULT
1550 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1552 /* delete tooltip control */
1553 if (infoPtr->hwndToolTip)
1554 DestroyWindow (infoPtr->hwndToolTip);
1556 Free (infoPtr->tics);
1557 infoPtr->tics = NULL;
1559 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1560 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1561 Free (infoPtr);
1563 return 0;
1567 static LRESULT
1568 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1570 TRACE("\n");
1571 infoPtr->bFocussed = FALSE;
1572 TRACKBAR_InvalidateAll(infoPtr);
1574 return 0;
1577 static LRESULT
1578 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1580 POINT clickPoint;
1582 clickPoint.x = x;
1583 clickPoint.y = y;
1585 SetFocus(infoPtr->hwndSelf);
1587 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1588 infoPtr->flags |= TB_DRAG_MODE;
1589 SetCapture (infoPtr->hwndSelf);
1590 TRACKBAR_UpdateToolTip (infoPtr);
1591 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1592 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1593 } else {
1594 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1595 if (dir == 0) return 0;
1596 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1597 TRACKBAR_AutoPage (infoPtr, clickPoint);
1598 SetCapture (infoPtr->hwndSelf);
1599 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1602 return 0;
1606 static LRESULT
1607 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1609 if (infoPtr->flags & TB_DRAG_MODE) {
1610 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1611 notify_with_scroll (infoPtr, TB_ENDTRACK);
1612 infoPtr->flags &= ~TB_DRAG_MODE;
1613 ReleaseCapture ();
1614 notify(infoPtr, NM_RELEASEDCAPTURE);
1615 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1616 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1618 if (infoPtr->flags & TB_AUTO_PAGE) {
1619 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1620 infoPtr->flags &= ~TB_AUTO_PAGE;
1621 notify_with_scroll (infoPtr, TB_ENDTRACK);
1622 ReleaseCapture ();
1623 notify(infoPtr, NM_RELEASEDCAPTURE);
1626 return 0;
1630 static LRESULT
1631 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1633 notify_with_scroll (infoPtr, TB_ENDTRACK);
1634 return 0;
1638 static LRESULT
1639 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1641 if (hdc) {
1642 TRACKBAR_Refresh(infoPtr, hdc);
1643 } else {
1644 PAINTSTRUCT ps;
1645 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1646 TRACKBAR_Refresh (infoPtr, hdc);
1647 EndPaint (infoPtr->hwndSelf, &ps);
1650 return 0;
1654 static LRESULT
1655 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1657 TRACE("\n");
1658 infoPtr->bFocussed = TRUE;
1659 TRACKBAR_InvalidateAll(infoPtr);
1661 return 0;
1665 static LRESULT
1666 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1668 if (infoPtr->dwStyle & TBS_FIXEDLENGTH)
1670 TRACKBAR_CalcChannel(infoPtr);
1671 TRACKBAR_UpdateThumb(infoPtr);
1673 else
1674 TRACKBAR_InitializeThumb(infoPtr);
1675 TRACKBAR_AlignBuddies (infoPtr);
1676 TRACKBAR_InvalidateAll(infoPtr);
1678 return 0;
1681 static LRESULT
1682 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1683 const STYLESTRUCT *lpss)
1685 if (wStyleType != GWL_STYLE) return 0;
1687 infoPtr->dwStyle = lpss->styleNew;
1689 return 0;
1692 static LRESULT
1693 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1695 if (infoPtr->flags & TB_AUTO_PAGE) {
1696 POINT pt;
1697 if (GetCursorPos(&pt))
1698 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1699 TRACKBAR_AutoPage(infoPtr, pt);
1701 return 0;
1705 /* update theme after a WM_THEMECHANGED message */
1706 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1708 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1709 CloseThemeData (theme);
1710 OpenThemeData (infoPtr->hwndSelf, themeClass);
1711 return 0;
1715 static LRESULT
1716 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1718 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1719 LONG dragPos, oldPos = infoPtr->lPos;
1721 TRACE("(x=%d. y=%d)\n", x, y);
1723 if (infoPtr->flags & TB_AUTO_PAGE) {
1724 POINT pt;
1725 pt.x = x;
1726 pt.y = y;
1727 TRACKBAR_AutoPage (infoPtr, pt);
1728 return TRUE;
1731 if (!(infoPtr->flags & TB_DRAG_MODE))
1733 if (GetWindowTheme (infoPtr->hwndSelf))
1735 DWORD oldFlags = infoPtr->flags;
1736 POINT pt;
1737 pt.x = x;
1738 pt.y = y;
1739 if (PtInRect (&infoPtr->rcThumb, pt))
1741 TRACKMOUSEEVENT tme;
1742 tme.cbSize = sizeof( tme );
1743 tme.dwFlags = TME_LEAVE;
1744 tme.hwndTrack = infoPtr->hwndSelf;
1745 TrackMouseEvent( &tme );
1746 infoPtr->flags |= TB_THUMB_HOT;
1748 else
1750 TRACKMOUSEEVENT tme;
1751 tme.cbSize = sizeof( tme );
1752 tme.dwFlags = TME_CANCEL;
1753 tme.hwndTrack = infoPtr->hwndSelf;
1754 TrackMouseEvent( &tme );
1755 infoPtr->flags &= ~TB_THUMB_HOT;
1757 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1759 return TRUE;
1762 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1764 if (dragPos == oldPos) return TRUE;
1766 infoPtr->lPos = dragPos;
1767 TRACKBAR_UpdateThumb (infoPtr);
1769 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1771 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1772 UpdateWindow (infoPtr->hwndSelf);
1774 return TRUE;
1777 static BOOL
1778 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1780 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1781 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1782 LONG pos = infoPtr->lPos;
1784 TRACE("%x\n", nVirtKey);
1786 switch (nVirtKey) {
1787 case VK_UP:
1788 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1789 else TRACKBAR_LineUp(infoPtr);
1790 break;
1791 case VK_LEFT:
1792 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1793 else TRACKBAR_LineUp(infoPtr);
1794 break;
1795 case VK_DOWN:
1796 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1797 else TRACKBAR_LineDown(infoPtr);
1798 break;
1799 case VK_RIGHT:
1800 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1801 else TRACKBAR_LineDown(infoPtr);
1802 break;
1803 case VK_NEXT:
1804 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1805 else TRACKBAR_PageDown(infoPtr);
1806 break;
1807 case VK_PRIOR:
1808 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1809 else TRACKBAR_PageUp(infoPtr);
1810 break;
1811 case VK_HOME:
1812 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1813 infoPtr->lPos = infoPtr->lRangeMin;
1814 notify_with_scroll (infoPtr, TB_TOP);
1815 break;
1816 case VK_END:
1817 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1818 infoPtr->lPos = infoPtr->lRangeMax;
1819 notify_with_scroll (infoPtr, TB_BOTTOM);
1820 break;
1823 if (pos != infoPtr->lPos) {
1824 TRACKBAR_UpdateThumb (infoPtr);
1825 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1828 return TRUE;
1832 static inline BOOL
1833 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1835 switch (nVirtKey) {
1836 case VK_LEFT:
1837 case VK_UP:
1838 case VK_RIGHT:
1839 case VK_DOWN:
1840 case VK_NEXT:
1841 case VK_PRIOR:
1842 case VK_HOME:
1843 case VK_END:
1844 notify_with_scroll (infoPtr, TB_ENDTRACK);
1846 return TRUE;
1850 static LRESULT
1851 TRACKBAR_Enable (TRACKBAR_INFO *infoPtr, BOOL enable)
1853 if (enable)
1854 infoPtr->dwStyle &= ~WS_DISABLED;
1855 else
1856 infoPtr->dwStyle |= WS_DISABLED;
1858 InvalidateRect(infoPtr->hwndSelf, &infoPtr->rcThumb, TRUE);
1860 return 1;
1863 static LRESULT WINAPI
1864 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1866 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1868 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1870 if (!infoPtr && (uMsg != WM_CREATE))
1871 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1873 switch (uMsg)
1875 case TBM_CLEARSEL:
1876 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1878 case TBM_CLEARTICS:
1879 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1881 case TBM_GETBUDDY:
1882 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1884 case TBM_GETCHANNELRECT:
1885 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1887 case TBM_GETLINESIZE:
1888 return infoPtr->lLineSize;
1890 case TBM_GETNUMTICS:
1891 return TRACKBAR_GetNumTics (infoPtr);
1893 case TBM_GETPAGESIZE:
1894 return infoPtr->lPageSize;
1896 case TBM_GETPOS:
1897 return infoPtr->lPos;
1899 case TBM_GETPTICS:
1900 return (LRESULT)infoPtr->tics;
1902 case TBM_GETRANGEMAX:
1903 return infoPtr->lRangeMax;
1905 case TBM_GETRANGEMIN:
1906 return infoPtr->lRangeMin;
1908 case TBM_GETSELEND:
1909 return infoPtr->lSelMax;
1911 case TBM_GETSELSTART:
1912 return infoPtr->lSelMin;
1914 case TBM_GETTHUMBLENGTH:
1915 return infoPtr->uThumbLen;
1917 case TBM_GETTHUMBRECT:
1918 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1920 case TBM_GETTIC:
1921 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1923 case TBM_GETTICPOS:
1924 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1926 case TBM_GETTOOLTIPS:
1927 return (LRESULT)infoPtr->hwndToolTip;
1929 case TBM_GETUNICODEFORMAT:
1930 return infoPtr->bUnicode;
1932 case TBM_SETBUDDY:
1933 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1935 case TBM_SETLINESIZE:
1936 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1938 case TBM_SETPAGESIZE:
1939 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1941 case TBM_SETPOS:
1942 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1944 case TBM_SETRANGE:
1945 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1947 case TBM_SETRANGEMAX:
1948 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1950 case TBM_SETRANGEMIN:
1951 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1953 case TBM_SETSEL:
1954 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1956 case TBM_SETSELEND:
1957 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1959 case TBM_SETSELSTART:
1960 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1962 case TBM_SETTHUMBLENGTH:
1963 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1965 case TBM_SETTIC:
1966 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1968 case TBM_SETTICFREQ:
1969 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1971 case TBM_SETTIPSIDE:
1972 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1974 case TBM_SETTOOLTIPS:
1975 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1977 case TBM_SETUNICODEFORMAT:
1978 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1981 case WM_CAPTURECHANGED:
1982 if (hwnd == (HWND)lParam) return 0;
1983 return TRACKBAR_CaptureChanged (infoPtr);
1985 case WM_CREATE:
1986 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1988 case WM_DESTROY:
1989 return TRACKBAR_Destroy (infoPtr);
1991 case WM_ENABLE:
1992 return TRACKBAR_Enable (infoPtr, (BOOL)wParam);
1994 case WM_ERASEBKGND:
1995 return 0;
1997 case WM_GETDLGCODE:
1998 return DLGC_WANTARROWS;
2000 case WM_KEYDOWN:
2001 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
2003 case WM_KEYUP:
2004 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
2006 case WM_KILLFOCUS:
2007 return TRACKBAR_KillFocus (infoPtr);
2009 case WM_LBUTTONDOWN:
2010 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2012 case WM_LBUTTONUP:
2013 return TRACKBAR_LButtonUp (infoPtr);
2015 case WM_MOUSELEAVE:
2016 infoPtr->flags &= ~TB_THUMB_HOT;
2017 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
2018 return 0;
2020 case WM_MOUSEMOVE:
2021 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2023 case WM_PRINTCLIENT:
2024 case WM_PAINT:
2025 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
2027 case WM_SETFOCUS:
2028 return TRACKBAR_SetFocus (infoPtr);
2030 case WM_SIZE:
2031 return TRACKBAR_Size (infoPtr);
2033 case WM_STYLECHANGED:
2034 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2036 case WM_THEMECHANGED:
2037 return theme_changed (infoPtr);
2039 case WM_TIMER:
2040 return TRACKBAR_Timer (infoPtr);
2042 case WM_WININICHANGE:
2043 return TRACKBAR_InitializeThumb (infoPtr);
2045 default:
2046 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2047 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2048 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2053 void TRACKBAR_Register (void)
2055 WNDCLASSW wndClass;
2057 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2058 wndClass.style = CS_GLOBALCLASS;
2059 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
2060 wndClass.cbClsExtra = 0;
2061 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
2062 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2063 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2064 wndClass.lpszClassName = TRACKBAR_CLASSW;
2066 RegisterClassW (&wndClass);
2070 void TRACKBAR_Unregister (void)
2072 UnregisterClassW (TRACKBAR_CLASSW, NULL);