wbemprox: Rewrite IWbemServices::ExecMethod with low-level functions so we can reuse...
[wine.git] / dlls / comctl32 / trackbar.c
blob50c44d5c5480d305f54bab5b371321d33967f557
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>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "winnls.h"
43 #include "commctrl.h"
44 #include "uxtheme.h"
45 #include "vssym32.h"
46 #include "wine/debug.h"
48 #include "comctl32.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
52 typedef struct
54 HWND hwndSelf;
55 DWORD dwStyle;
56 LONG lRangeMin;
57 LONG lRangeMax;
58 LONG lLineSize;
59 LONG lPageSize;
60 LONG lSelMin;
61 LONG lSelMax;
62 LONG lPos;
63 UINT uThumbLen;
64 UINT uNumTics;
65 UINT uTicFreq;
66 HWND hwndNotify;
67 HWND hwndToolTip;
68 HWND hwndBuddyLA;
69 HWND hwndBuddyRB;
70 INT fLocation;
71 INT flags;
72 BOOL bUnicode;
73 BOOL bFocussed;
74 RECT rcChannel;
75 RECT rcSelection;
76 RECT rcThumb;
77 LPLONG tics;
78 } TRACKBAR_INFO;
80 #define TB_REFRESH_TIMER 1
81 #define TB_REFRESH_DELAY 500
83 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
85 #define TB_DEFAULTPAGESIZE 20
87 /* Used by TRACKBAR_Refresh to find out which parts of the control
88 need to be recalculated */
90 #define TB_THUMBPOSCHANGED 1
91 #define TB_THUMBSIZECHANGED 2
92 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
93 #define TB_SELECTIONCHANGED 4
94 #define TB_DRAG_MODE 8 /* we're dragging the slider */
95 #define TB_AUTO_PAGE_LEFT 16
96 #define TB_AUTO_PAGE_RIGHT 32
97 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
98 #define TB_THUMB_HOT 64 /* mouse hovers above thumb */
100 /* helper defines for TRACKBAR_DrawTic */
101 #define TIC_EDGE 0x20
102 #define TIC_SELECTIONMARKMAX 0x80
103 #define TIC_SELECTIONMARKMIN 0x100
104 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
106 static const WCHAR themeClass[] = { 'T','r','a','c','k','b','a','r',0 };
108 static inline int
109 notify_customdraw (const TRACKBAR_INFO *infoPtr, NMCUSTOMDRAW *pnmcd, int stage)
111 pnmcd->dwDrawStage = stage;
112 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
113 pnmcd->hdr.idFrom, (LPARAM)pnmcd);
116 static LRESULT notify_hdr (const TRACKBAR_INFO *infoPtr, INT code, LPNMHDR pnmh)
118 LRESULT result;
120 TRACE("(code=%d)\n", code);
122 pnmh->hwndFrom = infoPtr->hwndSelf;
123 pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
124 pnmh->code = code;
125 result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
127 TRACE(" <= %ld\n", result);
129 return result;
132 static inline int notify (const TRACKBAR_INFO *infoPtr, INT code)
134 NMHDR nmh;
135 return notify_hdr(infoPtr, code, &nmh);
138 static void notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code)
140 UINT scroll = infoPtr->dwStyle & TBS_VERT ? WM_VSCROLL : WM_HSCROLL;
142 TRACE("%x\n", code);
144 SendMessageW (infoPtr->hwndNotify, scroll, code, (LPARAM)infoPtr->hwndSelf);
147 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
149 int tic;
150 unsigned nrTics, i;
152 if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin) {
153 nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
154 /* don't add extra tic if there's no remainder */
155 if (nrTics && ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0))
156 nrTics--;
158 else {
159 Free (infoPtr->tics);
160 infoPtr->tics = NULL;
161 infoPtr->uNumTics = 0;
162 return;
165 if (nrTics != infoPtr->uNumTics) {
166 infoPtr->tics=ReAlloc (infoPtr->tics,
167 (nrTics+1)*sizeof (DWORD));
168 if (!infoPtr->tics) {
169 infoPtr->uNumTics = 0;
170 notify(infoPtr, NM_OUTOFMEMORY);
171 return;
173 infoPtr->uNumTics = nrTics;
176 tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
177 for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
178 infoPtr->tics[i] = tic;
181 /* converts from physical (mouse) position to logical position
182 (in range of trackbar) */
184 static inline LONG
185 TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place)
187 double range, width, pos, offsetthumb;
189 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
190 if (infoPtr->dwStyle & TBS_VERT) {
191 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
192 width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2) - 1;
193 pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
194 } else {
195 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
196 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2) - 1;
197 pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
199 pos += infoPtr->lRangeMin;
200 if (pos > infoPtr->lRangeMax)
201 pos = infoPtr->lRangeMax;
202 else if (pos < infoPtr->lRangeMin)
203 pos = infoPtr->lRangeMin;
205 TRACE("%.2f\n", pos);
206 return (LONG)(pos + 0.5);
210 /* return: 0> prev, 0 none, >0 next */
211 static LONG
212 TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint)
214 RECT pageRect;
216 if (infoPtr->dwStyle & TBS_VERT) {
217 pageRect.top = infoPtr->rcChannel.top;
218 pageRect.bottom = infoPtr->rcChannel.bottom;
219 pageRect.left = infoPtr->rcThumb.left;
220 pageRect.right = infoPtr->rcThumb.right;
221 } else {
222 pageRect.top = infoPtr->rcThumb.top;
223 pageRect.bottom = infoPtr->rcThumb.bottom;
224 pageRect.left = infoPtr->rcChannel.left;
225 pageRect.right = infoPtr->rcChannel.right;
229 if (PtInRect(&pageRect, clickPoint))
231 int clickPlace = (infoPtr->dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
233 LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace);
235 return clickPos - infoPtr->lPos;
238 return 0;
241 static inline void
242 TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
244 if (infoPtr->lPos == infoPtr->lRangeMax) return;
246 infoPtr->lPos += infoPtr->lPageSize;
247 if (infoPtr->lPos > infoPtr->lRangeMax)
248 infoPtr->lPos = infoPtr->lRangeMax;
249 notify_with_scroll (infoPtr, TB_PAGEDOWN);
253 static inline void
254 TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
256 if (infoPtr->lPos == infoPtr->lRangeMin) return;
258 infoPtr->lPos -= infoPtr->lPageSize;
259 if (infoPtr->lPos < infoPtr->lRangeMin)
260 infoPtr->lPos = infoPtr->lRangeMin;
261 notify_with_scroll (infoPtr, TB_PAGEUP);
264 static inline void TRACKBAR_LineUp(TRACKBAR_INFO *infoPtr)
266 if (infoPtr->lPos == infoPtr->lRangeMin) return;
267 infoPtr->lPos -= infoPtr->lLineSize;
268 if (infoPtr->lPos < infoPtr->lRangeMin)
269 infoPtr->lPos = infoPtr->lRangeMin;
270 notify_with_scroll (infoPtr, TB_LINEUP);
273 static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr)
275 if (infoPtr->lPos == infoPtr->lRangeMax) return;
276 infoPtr->lPos += infoPtr->lLineSize;
277 if (infoPtr->lPos > infoPtr->lRangeMax)
278 infoPtr->lPos = infoPtr->lRangeMax;
279 notify_with_scroll (infoPtr, TB_LINEDOWN);
282 static void
283 TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
285 INT cyChannel, offsetthumb, offsetedge;
286 RECT lpRect, *channel = & infoPtr->rcChannel;
288 GetClientRect (infoPtr->hwndSelf, &lpRect);
290 offsetthumb = infoPtr->uThumbLen / 4;
291 offsetedge = offsetthumb + 3;
292 cyChannel = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4;
293 if (infoPtr->dwStyle & TBS_VERT) {
294 channel->top = lpRect.top + offsetedge;
295 channel->bottom = lpRect.bottom - offsetedge;
296 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
297 channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
298 else
299 channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
300 if (infoPtr->dwStyle & TBS_BOTH) {
301 if (infoPtr->dwStyle & TBS_NOTICKS)
302 channel->left += 1;
303 else
304 channel->left += 9;
306 else if (infoPtr->dwStyle & TBS_TOP) {
307 if (infoPtr->dwStyle & TBS_NOTICKS)
308 channel->left += 2;
309 else
310 channel->left += 10;
312 channel->right = channel->left + cyChannel;
313 } else {
314 channel->left = lpRect.left + offsetedge;
315 channel->right = lpRect.right - offsetedge;
316 if (infoPtr->dwStyle & TBS_ENABLESELRANGE)
317 channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2);
318 else
319 channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
320 if (infoPtr->dwStyle & TBS_BOTH) {
321 if (infoPtr->dwStyle & TBS_NOTICKS)
322 channel->top += 1;
323 else
324 channel->top += 9;
326 else if (infoPtr->dwStyle & TBS_TOP) {
327 if (infoPtr->dwStyle & TBS_NOTICKS)
328 channel->top += 2;
329 else
330 channel->top += 10;
332 channel->bottom = channel->top + cyChannel;
336 static void
337 TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
339 int range, width, height, thumbwidth;
340 RECT lpRect;
342 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
343 thumbwidth = (infoPtr->uThumbLen / 2) | 1;
345 if (!range) range = 1;
347 GetClientRect(infoPtr->hwndSelf, &lpRect);
348 if (infoPtr->dwStyle & TBS_VERT)
350 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth;
352 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_LEFT)) && !(infoPtr->dwStyle & TBS_NOTICKS))
353 thumb->left = 10;
354 else
355 thumb->left = 2;
356 thumb->right = thumb->left + infoPtr->uThumbLen;
357 thumb->top = infoPtr->rcChannel.top +
358 (height*(lPos - infoPtr->lRangeMin))/range;
359 thumb->bottom = thumb->top + thumbwidth;
361 else
363 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth;
365 thumb->left = infoPtr->rcChannel.left +
366 (width*(lPos - infoPtr->lRangeMin))/range;
367 thumb->right = thumb->left + thumbwidth;
368 if ((infoPtr->dwStyle & (TBS_BOTH | TBS_TOP)) && !(infoPtr->dwStyle & TBS_NOTICKS))
369 thumb->top = 10;
370 else
371 thumb->top = 2;
372 thumb->bottom = thumb->top + infoPtr->uThumbLen;
376 static inline void
377 TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
379 TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
382 static inline void
383 TRACKBAR_InvalidateAll (const TRACKBAR_INFO *infoPtr)
385 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
388 static void
389 TRACKBAR_InvalidateThumb (const TRACKBAR_INFO *infoPtr, LONG thumbPos)
391 RECT rcThumb;
393 TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
394 InflateRect(&rcThumb, 1, 1);
395 InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
398 static inline void
399 TRACKBAR_InvalidateThumbMove (const TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
401 TRACKBAR_InvalidateThumb (infoPtr, oldPos);
402 if (newPos != oldPos)
403 TRACKBAR_InvalidateThumb (infoPtr, newPos);
406 static inline BOOL
407 TRACKBAR_HasSelection (const TRACKBAR_INFO *infoPtr)
409 return infoPtr->lSelMin != infoPtr->lSelMax;
412 static void
413 TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
415 RECT *selection = &infoPtr->rcSelection;
416 int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
417 int offsetthumb, height, width;
419 if (range <= 0) {
420 SetRectEmpty (selection);
421 } else {
422 if (infoPtr->dwStyle & TBS_VERT) {
423 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
424 height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2;
425 selection->top = infoPtr->rcChannel.top + offsetthumb +
426 (height*infoPtr->lSelMin)/range;
427 selection->bottom = infoPtr->rcChannel.top + offsetthumb +
428 (height*infoPtr->lSelMax)/range;
429 selection->left = infoPtr->rcChannel.left + 3;
430 selection->right = infoPtr->rcChannel.right - 3;
431 } else {
432 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
433 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
434 selection->left = infoPtr->rcChannel.left + offsetthumb +
435 (width*infoPtr->lSelMin)/range;
436 selection->right = infoPtr->rcChannel.left + offsetthumb +
437 (width*infoPtr->lSelMax)/range;
438 selection->top = infoPtr->rcChannel.top + 3;
439 selection->bottom = infoPtr->rcChannel.bottom - 3;
443 TRACE("selection[%s]\n", wine_dbgstr_rect(selection));
446 static BOOL
447 TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
449 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
450 LONG prevPos = infoPtr->lPos;
452 TRACE("x=%d, y=%d, dir=%d\n", clickPoint.x, clickPoint.y, dir);
454 if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
455 TRACKBAR_PageDown(infoPtr);
456 else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
457 TRACKBAR_PageUp(infoPtr);
458 else return FALSE;
460 TRACKBAR_UpdateThumb (infoPtr);
461 TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
463 return TRUE;
466 /* Trackbar drawing code. I like my spaghetti done milanese. */
468 static void
469 TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc)
471 RECT rcChannel = infoPtr->rcChannel;
472 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
474 if (theme)
476 DrawThemeBackground (theme, hdc,
477 (infoPtr->dwStyle & TBS_VERT) ?
478 TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0);
480 else
482 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
483 if (infoPtr->dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
484 FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
485 if (TRACKBAR_HasSelection(infoPtr))
486 FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
491 static void
492 TRACKBAR_DrawOneTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
494 int x, y, ox, oy, range, side, indent = 0, len = 3;
495 int offsetthumb;
496 RECT rcTics;
498 if (flags & TBS_VERT) {
499 offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2;
500 rcTics.left = infoPtr->rcThumb.left - 2;
501 rcTics.right = infoPtr->rcThumb.right + 2;
502 rcTics.top = infoPtr->rcChannel.top + offsetthumb;
503 rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb - 1;
504 } else {
505 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
506 rcTics.left = infoPtr->rcChannel.left + offsetthumb;
507 rcTics.right = infoPtr->rcChannel.right - offsetthumb - 1;
508 rcTics.top = infoPtr->rcThumb.top - 2;
509 rcTics.bottom = infoPtr->rcThumb.bottom + 2;
512 if (flags & (TBS_TOP | TBS_LEFT)) {
513 x = rcTics.left;
514 y = rcTics.top;
515 side = -1;
516 } else {
517 x = rcTics.right;
518 y = rcTics.bottom;
519 side = 1;
522 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
523 if (range <= 0)
524 range = 1; /* to avoid division by zero */
526 if (flags & TIC_SELECTIONMARK) {
527 indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
528 } else if (flags & TIC_EDGE) {
529 len++;
532 if (flags & TBS_VERT) {
533 int height = rcTics.bottom - rcTics.top;
534 y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
535 } else {
536 int width = rcTics.right - rcTics.left;
537 x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
540 ox = x;
541 oy = y;
542 MoveToEx(hdc, x, y, 0);
543 if (flags & TBS_VERT) x += len * side;
544 else y += len * side;
545 LineTo(hdc, x, y);
547 if (flags & TIC_SELECTIONMARK) {
548 if (flags & TBS_VERT) {
549 x -= side;
550 } else {
551 y -= side;
553 MoveToEx(hdc, x, y, 0);
554 if (flags & TBS_VERT) {
555 y += 2 * indent;
556 } else {
557 x += 2 * indent;
560 LineTo(hdc, x, y);
561 LineTo(hdc, ox, oy);
566 static inline void
567 TRACKBAR_DrawTic (const TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
569 if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
570 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
572 if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
573 TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
576 static void
577 TRACKBAR_DrawTics (const TRACKBAR_INFO *infoPtr, HDC hdc)
579 unsigned int i;
580 int ticFlags = infoPtr->dwStyle & 0x0f;
581 LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
582 HPEN hOldPen, hTicPen;
583 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
585 if (theme)
587 int part = (infoPtr->dwStyle & TBS_VERT) ? TKP_TICSVERT : TKP_TICS;
588 GetThemeColor (theme, part, TSS_NORMAL, TMT_COLOR, &ticPen.lopnColor);
590 /* create the pen to draw the tics with */
591 hTicPen = CreatePenIndirect(&ticPen);
592 hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
594 /* actually draw the tics */
595 for (i=0; i<infoPtr->uNumTics; i++)
596 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
598 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
599 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
601 if ((infoPtr->dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
602 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
603 ticFlags | TIC_SELECTIONMARKMIN);
604 TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
605 ticFlags | TIC_SELECTIONMARKMAX);
608 /* clean up the pen, if we created one */
609 if (hTicPen) {
610 SelectObject(hdc, hOldPen);
611 DeleteObject(hTicPen);
615 static int
616 TRACKBAR_FillThumb (const TRACKBAR_INFO *infoPtr, HDC hdc, HBRUSH hbrush)
618 const RECT *thumb = &infoPtr->rcThumb;
619 const int PointCount = 6;
620 POINT points[PointCount];
621 int PointDepth;
622 HBRUSH oldbr;
624 if (infoPtr->dwStyle & TBS_BOTH)
626 FillRect(hdc, thumb, hbrush);
627 return 0;
630 if (infoPtr->dwStyle & TBS_VERT)
632 PointDepth = (thumb->bottom - thumb->top) / 2;
633 if (infoPtr->dwStyle & TBS_LEFT)
635 points[0].x = thumb->right-1;
636 points[0].y = thumb->top;
637 points[1].x = thumb->right-1;
638 points[1].y = thumb->bottom-1;
639 points[2].x = thumb->left + PointDepth;
640 points[2].y = thumb->bottom-1;
641 points[3].x = thumb->left;
642 points[3].y = thumb->top + PointDepth;
643 points[4].x = thumb->left + PointDepth;
644 points[4].y = thumb->top;
645 points[5].x = points[0].x;
646 points[5].y = points[0].y;
648 else
650 points[0].x = thumb->right;
651 points[0].y = thumb->top + PointDepth;
652 points[1].x = thumb->right - PointDepth;
653 points[1].y = thumb->bottom-1;
654 points[2].x = thumb->left;
655 points[2].y = thumb->bottom-1;
656 points[3].x = thumb->left;
657 points[3].y = thumb->top;
658 points[4].x = thumb->right - PointDepth;
659 points[4].y = thumb->top;
660 points[5].x = points[0].x;
661 points[5].y = points[0].y;
664 else
666 PointDepth = (thumb->right - thumb->left) / 2;
667 if (infoPtr->dwStyle & TBS_TOP)
669 points[0].x = thumb->left + PointDepth;
670 points[0].y = thumb->top+1;
671 points[1].x = thumb->right-1;
672 points[1].y = thumb->top + PointDepth + 1;
673 points[2].x = thumb->right-1;
674 points[2].y = thumb->bottom-1;
675 points[3].x = thumb->left;
676 points[3].y = thumb->bottom-1;
677 points[4].x = thumb->left;
678 points[4].y = thumb->top + PointDepth + 1;
679 points[5].x = points[0].x;
680 points[5].y = points[0].y;
682 else
684 points[0].x = thumb->right-1;
685 points[0].y = thumb->top;
686 points[1].x = thumb->right-1;
687 points[1].y = thumb->bottom - PointDepth - 1;
688 points[2].x = thumb->left + PointDepth;
689 points[2].y = thumb->bottom-1;
690 points[3].x = thumb->left;
691 points[3].y = thumb->bottom - PointDepth - 1;
692 points[4].x = thumb->left;
693 points[4].y = thumb->top;
694 points[5].x = points[0].x;
695 points[5].y = points[0].y;
699 oldbr = SelectObject(hdc, hbrush);
700 SetPolyFillMode(hdc, WINDING);
701 Polygon(hdc, points, PointCount);
702 SelectObject(hdc, oldbr);
704 return PointDepth;
707 static void
708 TRACKBAR_DrawThumb (TRACKBAR_INFO *infoPtr, HDC hdc)
710 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
711 int PointDepth;
712 HBRUSH brush;
714 if (theme)
716 int partId;
717 int stateId;
718 if (infoPtr->dwStyle & TBS_BOTH)
719 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBVERT : TKP_THUMB;
720 else if (infoPtr->dwStyle & TBS_LEFT)
721 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBLEFT : TKP_THUMBTOP;
722 else
723 partId = (infoPtr->dwStyle & TBS_VERT) ? TKP_THUMBRIGHT : TKP_THUMBBOTTOM;
725 if (infoPtr->dwStyle & WS_DISABLED)
726 stateId = TUS_DISABLED;
727 else if (infoPtr->flags & TB_DRAG_MODE)
728 stateId = TUS_PRESSED;
729 else if (infoPtr->flags & TB_THUMB_HOT)
730 stateId = TUS_HOT;
731 else
732 stateId = TUS_NORMAL;
734 DrawThemeBackground (theme, hdc, partId, stateId, &infoPtr->rcThumb, NULL);
736 return;
739 if (infoPtr->dwStyle & WS_DISABLED || infoPtr->flags & TB_DRAG_MODE)
741 if (comctl32_color.clr3dHilight == comctl32_color.clrWindow)
742 brush = COMCTL32_hPattern55AABrush;
743 else
744 brush = GetSysColorBrush(COLOR_SCROLLBAR);
746 SetTextColor(hdc, comctl32_color.clr3dFace);
747 SetBkColor(hdc, comctl32_color.clr3dHilight);
749 else
750 brush = GetSysColorBrush(COLOR_BTNFACE);
752 PointDepth = TRACKBAR_FillThumb(infoPtr, hdc, brush);
754 if (infoPtr->dwStyle & TBS_BOTH)
756 DrawEdge(hdc, &infoPtr->rcThumb, EDGE_RAISED, BF_RECT | BF_SOFT);
757 return;
759 else
761 RECT thumb = infoPtr->rcThumb;
763 if (infoPtr->dwStyle & TBS_VERT)
765 if (infoPtr->dwStyle & TBS_LEFT)
767 /* rectangular part */
768 thumb.left += PointDepth;
769 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_RIGHT | BF_BOTTOM | BF_SOFT);
771 /* light edge */
772 thumb.left -= PointDepth;
773 thumb.right = thumb.left + PointDepth;
774 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
775 thumb.top = infoPtr->rcThumb.top;
776 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
778 /* shadowed edge */
779 thumb.top += PointDepth;
780 thumb.bottom += PointDepth;
781 DrawEdge(hdc, &thumb, EDGE_SUNKEN, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
782 return;
784 else
786 /* rectangular part */
787 thumb.right -= PointDepth;
788 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_TOP | BF_LEFT | BF_BOTTOM | BF_SOFT);
790 /* light edge */
791 thumb.left = thumb.right;
792 thumb.right += PointDepth + 1;
793 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
794 thumb.top = infoPtr->rcThumb.top;
795 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
797 /* shadowed edge */
798 thumb.top += PointDepth;
799 thumb.bottom += PointDepth;
800 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
803 else
805 if (infoPtr->dwStyle & TBS_TOP)
807 /* rectangular part */
808 thumb.top += PointDepth;
809 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_BOTTOM | BF_RIGHT | BF_SOFT);
811 /* light edge */
812 thumb.left = infoPtr->rcThumb.left;
813 thumb.right = thumb.left + PointDepth;
814 thumb.bottom = infoPtr->rcThumb.top + PointDepth + 1;
815 thumb.top -= PointDepth;
816 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPRIGHT | BF_SOFT);
818 /* shadowed edge */
819 thumb.left += PointDepth;
820 thumb.right += PointDepth;
821 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMRIGHT | BF_SOFT);
823 else
825 /* rectangular part */
826 thumb.bottom -= PointDepth;
827 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT);
829 /* light edge */
830 thumb.left = infoPtr->rcThumb.left;
831 thumb.right = thumb.left + PointDepth;
832 thumb.top = infoPtr->rcThumb.bottom - PointDepth - 1;
833 thumb.bottom += PointDepth;
834 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDTOPLEFT | BF_SOFT);
836 /* shadowed edge */
837 thumb.left += PointDepth;
838 thumb.right += PointDepth;
839 DrawEdge(hdc, &thumb, EDGE_RAISED, BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT);
846 static inline void
847 TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow)
849 TTTOOLINFOW ti;
851 if (!infoPtr->hwndToolTip) return;
853 ZeroMemory(&ti, sizeof(ti));
854 ti.cbSize = sizeof(ti);
855 ti.hwnd = infoPtr->hwndSelf;
857 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
861 static void
862 TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr)
864 WCHAR buf[80];
865 static const WCHAR fmt[] = { '%', 'l', 'd', 0 };
866 TTTOOLINFOW ti;
867 POINT pt;
868 RECT rcClient;
869 LRESULT size;
871 if (!infoPtr->hwndToolTip) return;
873 ZeroMemory(&ti, sizeof(ti));
874 ti.cbSize = sizeof(ti);
875 ti.hwnd = infoPtr->hwndSelf;
876 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
878 wsprintfW (buf, fmt, infoPtr->lPos);
879 ti.lpszText = buf;
880 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
882 GetClientRect (infoPtr->hwndSelf, &rcClient);
883 size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
884 if (infoPtr->dwStyle & TBS_VERT) {
885 if (infoPtr->fLocation == TBTS_LEFT)
886 pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
887 else
888 pt.x = rcClient.right + TOOLTIP_OFFSET;
889 pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
890 } else {
891 if (infoPtr->fLocation == TBTS_TOP)
892 pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
893 else
894 pt.y = rcClient.bottom + TOOLTIP_OFFSET;
895 pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
897 ClientToScreen(infoPtr->hwndSelf, &pt);
899 SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
900 0, MAKELPARAM(pt.x, pt.y));
904 static void
905 TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
907 RECT rcClient;
908 HDC hdc;
909 HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
910 NMCUSTOMDRAW nmcd;
911 int gcdrf, icdrf;
913 if (infoPtr->flags & TB_THUMBCHANGED) {
914 TRACKBAR_UpdateThumb (infoPtr);
915 if (infoPtr->flags & TB_THUMBSIZECHANGED)
916 TRACKBAR_CalcChannel (infoPtr);
918 if (infoPtr->flags & TB_SELECTIONCHANGED)
919 TRACKBAR_CalcSelection (infoPtr);
921 if (infoPtr->flags & TB_DRAG_MODE)
922 TRACKBAR_UpdateToolTip (infoPtr);
924 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
926 GetClientRect (infoPtr->hwndSelf, &rcClient);
928 /* try to render offscreen, if we fail, carrry onscreen */
929 hdc = CreateCompatibleDC(hdcDst);
930 if (hdc) {
931 hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
932 if (hOffScreenBmp) {
933 hOldBmp = SelectObject(hdc, hOffScreenBmp);
934 } else {
935 DeleteObject(hdc);
936 hdc = hdcDst;
938 } else {
939 hdc = hdcDst;
942 ZeroMemory(&nmcd, sizeof(nmcd));
943 nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
944 nmcd.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
945 nmcd.hdr.code = NM_CUSTOMDRAW;
946 nmcd.hdc = hdc;
948 /* start the paint cycle */
949 nmcd.rc = rcClient;
950 gcdrf = notify_customdraw(infoPtr, &nmcd, CDDS_PREPAINT);
951 if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
953 /* Erase background */
954 if (gcdrf == CDRF_DODEFAULT ||
955 notify_customdraw(infoPtr, &nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
956 if (GetWindowTheme (infoPtr->hwndSelf)) {
957 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, 0);
959 else
960 FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
961 if (gcdrf != CDRF_DODEFAULT)
962 notify_customdraw(infoPtr, &nmcd, CDDS_POSTERASE);
965 /* draw channel */
966 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
967 nmcd.dwItemSpec = TBCD_CHANNEL;
968 nmcd.uItemState = CDIS_DEFAULT;
969 nmcd.rc = infoPtr->rcChannel;
970 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
971 } else icdrf = CDRF_DODEFAULT;
972 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
973 TRACKBAR_DrawChannel (infoPtr, hdc);
974 if (icdrf & CDRF_NOTIFYPOSTPAINT)
975 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
979 /* draw tics */
980 if (!(infoPtr->dwStyle & TBS_NOTICKS)) {
981 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
982 nmcd.dwItemSpec = TBCD_TICS;
983 nmcd.uItemState = CDIS_DEFAULT;
984 nmcd.rc = rcClient;
985 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
986 } else icdrf = CDRF_DODEFAULT;
987 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
988 TRACKBAR_DrawTics (infoPtr, hdc);
989 if (icdrf & CDRF_NOTIFYPOSTPAINT)
990 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
994 /* draw thumb */
995 if (!(infoPtr->dwStyle & TBS_NOTHUMB)) {
996 if (gcdrf & CDRF_NOTIFYITEMDRAW) {
997 nmcd.dwItemSpec = TBCD_THUMB;
998 nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
999 nmcd.rc = infoPtr->rcThumb;
1000 icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT);
1001 } else icdrf = CDRF_DODEFAULT;
1002 if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
1003 TRACKBAR_DrawThumb(infoPtr, hdc);
1004 if (icdrf & CDRF_NOTIFYPOSTPAINT)
1005 notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT);
1009 /* draw focus rectangle */
1010 if (infoPtr->bFocussed) {
1011 DrawFocusRect(hdc, &rcClient);
1014 /* finish up the painting */
1015 if (gcdrf & CDRF_NOTIFYPOSTPAINT)
1016 notify_customdraw(infoPtr, &nmcd, CDDS_POSTPAINT);
1018 cleanup:
1019 /* cleanup, if we rendered offscreen */
1020 if (hdc != hdcDst) {
1021 BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
1022 SelectObject(hdc, hOldBmp);
1023 DeleteObject(hOffScreenBmp);
1024 DeleteObject(hdc);
1029 static void
1030 TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr)
1032 HWND hwndParent = GetParent (infoPtr->hwndSelf);
1033 RECT rcSelf, rcBuddy;
1034 INT x, y;
1036 GetWindowRect (infoPtr->hwndSelf, &rcSelf);
1037 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
1039 /* align buddy left or above */
1040 if (infoPtr->hwndBuddyLA) {
1041 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
1042 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1044 if (infoPtr->dwStyle & TBS_VERT) {
1045 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1046 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1047 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
1049 else {
1050 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
1051 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1052 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1055 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
1056 SWP_NOZORDER | SWP_NOSIZE);
1060 /* align buddy right or below */
1061 if (infoPtr->hwndBuddyRB) {
1062 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
1063 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
1065 if (infoPtr->dwStyle & TBS_VERT) {
1066 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
1067 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
1068 y = rcSelf.bottom;
1070 else {
1071 x = rcSelf.right;
1072 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
1073 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
1075 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
1076 SWP_NOZORDER | SWP_NOSIZE);
1081 static LRESULT
1082 TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1084 infoPtr->lSelMin = 0;
1085 infoPtr->lSelMax = 0;
1086 infoPtr->flags |= TB_SELECTIONCHANGED;
1088 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1090 return 0;
1094 static LRESULT
1095 TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
1097 if (infoPtr->tics) {
1098 Free (infoPtr->tics);
1099 infoPtr->tics = NULL;
1100 infoPtr->uNumTics = 0;
1103 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1105 return 0;
1109 static inline LRESULT
1110 TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc)
1112 if (lprc == NULL) return 0;
1114 lprc->left = infoPtr->rcChannel.left;
1115 lprc->right = infoPtr->rcChannel.right;
1116 lprc->bottom = infoPtr->rcChannel.bottom;
1117 lprc->top = infoPtr->rcChannel.top;
1119 return 0;
1123 static inline LONG
1124 TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr)
1126 if (infoPtr->dwStyle & TBS_NOTICKS) return 0;
1128 return infoPtr->uNumTics + 2;
1132 static int comp_tics (const void *ap, const void *bp)
1134 const DWORD a = *(const DWORD *)ap;
1135 const DWORD b = *(const DWORD *)bp;
1137 TRACE("(a=%d, b=%d)\n", a, b);
1138 if (a < b) return -1;
1139 if (a > b) return 1;
1140 return 0;
1144 static inline LONG
1145 TRACKBAR_GetTic (const TRACKBAR_INFO *infoPtr, INT iTic)
1147 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1148 return -1;
1150 qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
1151 return infoPtr->tics[iTic];
1155 static inline LONG
1156 TRACKBAR_GetTicPos (const TRACKBAR_INFO *infoPtr, INT iTic)
1158 LONG range, width, pos, tic;
1159 int offsetthumb;
1161 if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
1162 return -1;
1164 tic = TRACKBAR_GetTic (infoPtr, iTic);
1165 range = infoPtr->lRangeMax - infoPtr->lRangeMin;
1166 if (range <= 0) range = 1;
1167 offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2;
1168 width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - offsetthumb*2;
1169 pos = infoPtr->rcChannel.left + offsetthumb + (width * tic) / range;
1171 return pos;
1175 static HWND
1176 TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
1178 HWND hwndTemp;
1180 if (fLocation) {
1181 /* buddy is left or above */
1182 hwndTemp = infoPtr->hwndBuddyLA;
1183 infoPtr->hwndBuddyLA = hwndBuddy;
1185 else {
1186 /* buddy is right or below */
1187 hwndTemp = infoPtr->hwndBuddyRB;
1188 infoPtr->hwndBuddyRB = hwndBuddy;
1191 TRACKBAR_AlignBuddies (infoPtr);
1193 return hwndTemp;
1197 static inline LONG
1198 TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
1200 LONG lTemp = infoPtr->lLineSize;
1202 infoPtr->lLineSize = lLineSize;
1204 return lTemp;
1208 static inline LONG
1209 TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
1211 LONG lTemp = infoPtr->lPageSize;
1213 if (lPageSize != -1)
1214 infoPtr->lPageSize = lPageSize;
1215 else
1216 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1218 return lTemp;
1222 static inline LRESULT
1223 TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
1225 LONG oldPos = infoPtr->lPos;
1226 infoPtr->lPos = lPosition;
1228 if (infoPtr->lPos < infoPtr->lRangeMin)
1229 infoPtr->lPos = infoPtr->lRangeMin;
1231 if (infoPtr->lPos > infoPtr->lRangeMax)
1232 infoPtr->lPos = infoPtr->lRangeMax;
1233 infoPtr->flags |= TB_THUMBPOSCHANGED;
1235 if (fPosition && oldPos != lPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
1237 return 0;
1241 static inline LRESULT
1242 TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
1244 BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
1245 infoPtr->lRangeMax != (SHORT)HIWORD(range);
1247 infoPtr->lRangeMin = (SHORT)LOWORD(range);
1248 infoPtr->lRangeMax = (SHORT)HIWORD(range);
1250 if (infoPtr->lPos < infoPtr->lRangeMin) {
1251 infoPtr->lPos = infoPtr->lRangeMin;
1252 infoPtr->flags |= TB_THUMBPOSCHANGED;
1255 if (infoPtr->lPos > infoPtr->lRangeMax) {
1256 infoPtr->lPos = infoPtr->lRangeMax;
1257 infoPtr->flags |= TB_THUMBPOSCHANGED;
1260 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1261 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1263 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1264 TRACKBAR_RecalculateTics (infoPtr);
1266 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1268 return 0;
1272 static inline LRESULT
1273 TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMax)
1275 BOOL changed = infoPtr->lRangeMax != lMax;
1277 infoPtr->lRangeMax = lMax;
1278 if (infoPtr->lPos > infoPtr->lRangeMax) {
1279 infoPtr->lPos = infoPtr->lRangeMax;
1280 infoPtr->flags |= TB_THUMBPOSCHANGED;
1283 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1284 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1286 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1287 TRACKBAR_RecalculateTics (infoPtr);
1289 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1291 return 0;
1295 static inline LRESULT
1296 TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG lMin)
1298 BOOL changed = infoPtr->lRangeMin != lMin;
1300 infoPtr->lRangeMin = lMin;
1301 if (infoPtr->lPos < infoPtr->lRangeMin) {
1302 infoPtr->lPos = infoPtr->lRangeMin;
1303 infoPtr->flags |= TB_THUMBPOSCHANGED;
1306 infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
1307 if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
1309 if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
1310 TRACKBAR_RecalculateTics (infoPtr);
1312 if (redraw) TRACKBAR_InvalidateAll(infoPtr);
1314 return 0;
1318 static inline LRESULT
1319 TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
1321 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1322 infoPtr->lSelMin = 0;
1323 infoPtr->lSelMax = 0;
1324 return 0;
1327 infoPtr->lSelMin = (SHORT)LOWORD(lSel);
1328 infoPtr->lSelMax = (SHORT)HIWORD(lSel);
1329 infoPtr->flags |= TB_SELECTIONCHANGED;
1331 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1332 infoPtr->lSelMin = infoPtr->lRangeMin;
1333 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1334 infoPtr->lSelMax = infoPtr->lRangeMax;
1336 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1338 return 0;
1342 static inline LRESULT
1343 TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
1345 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1346 infoPtr->lSelMax = 0;
1347 return 0;
1350 infoPtr->lSelMax = lEnd;
1351 infoPtr->flags |= TB_SELECTIONCHANGED;
1353 if (infoPtr->lSelMax > infoPtr->lRangeMax)
1354 infoPtr->lSelMax = infoPtr->lRangeMax;
1356 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1358 return 0;
1362 static inline LRESULT
1363 TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
1365 if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){
1366 infoPtr->lSelMin = 0;
1367 return 0;
1370 infoPtr->lSelMin = lStart;
1371 infoPtr->flags |=TB_SELECTIONCHANGED;
1373 if (infoPtr->lSelMin < infoPtr->lRangeMin)
1374 infoPtr->lSelMin = infoPtr->lRangeMin;
1376 if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
1378 return 0;
1382 static inline LRESULT
1383 TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
1385 if (infoPtr->dwStyle & TBS_FIXEDLENGTH) {
1386 /* We're not supposed to check if it's really changed or not,
1387 just repaint in any case. */
1388 infoPtr->uThumbLen = iLength;
1389 infoPtr->flags |= TB_THUMBSIZECHANGED;
1390 TRACKBAR_InvalidateAll(infoPtr);
1393 return 0;
1397 static inline LRESULT
1398 TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
1400 if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
1401 return FALSE;
1403 TRACE("lPos=%d\n", lPos);
1405 infoPtr->uNumTics++;
1406 infoPtr->tics=ReAlloc( infoPtr->tics,
1407 (infoPtr->uNumTics)*sizeof (DWORD));
1408 if (!infoPtr->tics) {
1409 infoPtr->uNumTics = 0;
1410 notify(infoPtr, NM_OUTOFMEMORY);
1411 return FALSE;
1413 infoPtr->tics[infoPtr->uNumTics-1] = lPos;
1415 TRACKBAR_InvalidateAll(infoPtr);
1417 return TRUE;
1421 static inline LRESULT
1422 TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
1424 if (infoPtr->dwStyle & TBS_AUTOTICKS) {
1425 infoPtr->uTicFreq = wFreq;
1426 TRACKBAR_RecalculateTics (infoPtr);
1427 TRACKBAR_InvalidateAll(infoPtr);
1430 return 0;
1434 static inline INT
1435 TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
1437 INT fTemp = infoPtr->fLocation;
1439 infoPtr->fLocation = fLocation;
1441 return fTemp;
1445 static inline LRESULT
1446 TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
1448 infoPtr->hwndToolTip = hwndTT;
1450 return 0;
1454 static inline BOOL
1455 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
1457 BOOL bTemp = infoPtr->bUnicode;
1459 infoPtr->bUnicode = fUnicode;
1461 return bTemp;
1465 static LRESULT
1466 TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
1468 RECT rect;
1469 int clientWidth, clientMetric;
1471 /* initial thumb length */
1472 clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21;
1473 GetClientRect(infoPtr->hwndSelf,&rect);
1474 if (infoPtr->dwStyle & TBS_VERT) {
1475 clientWidth = rect.right - rect.left;
1476 } else {
1477 clientWidth = rect.bottom - rect.top;
1479 if (clientWidth >= clientMetric)
1480 infoPtr->uThumbLen = clientMetric;
1481 else
1482 infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
1484 TRACKBAR_CalcChannel (infoPtr);
1485 TRACKBAR_UpdateThumb (infoPtr);
1486 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1488 return 0;
1492 static LRESULT
1493 TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1495 TRACKBAR_INFO *infoPtr;
1497 infoPtr = Alloc (sizeof(TRACKBAR_INFO));
1498 if (!infoPtr) return -1;
1499 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1501 /* set default values */
1502 infoPtr->hwndSelf = hwnd;
1503 infoPtr->dwStyle = lpcs->style;
1504 infoPtr->lRangeMin = 0;
1505 infoPtr->lRangeMax = 100;
1506 infoPtr->lLineSize = 1;
1507 infoPtr->lPageSize = TB_DEFAULTPAGESIZE;
1508 infoPtr->lSelMin = 0;
1509 infoPtr->lSelMax = 0;
1510 infoPtr->lPos = 0;
1511 infoPtr->fLocation = TBTS_TOP;
1512 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1513 infoPtr->uTicFreq = 1;
1514 infoPtr->tics = NULL;
1515 infoPtr->hwndNotify= lpcs->hwndParent;
1517 TRACKBAR_InitializeThumb (infoPtr);
1519 /* Create tooltip control */
1520 if (infoPtr->dwStyle & TBS_TOOLTIPS) {
1522 infoPtr->hwndToolTip =
1523 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1524 CW_USEDEFAULT, CW_USEDEFAULT,
1525 CW_USEDEFAULT, CW_USEDEFAULT,
1526 hwnd, 0, 0, 0);
1528 if (infoPtr->hwndToolTip) {
1529 TTTOOLINFOW ti;
1530 ZeroMemory (&ti, sizeof(ti));
1531 ti.cbSize = sizeof(ti);
1532 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
1533 ti.hwnd = hwnd;
1535 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
1539 OpenThemeData (hwnd, themeClass);
1541 return 0;
1545 static LRESULT
1546 TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
1548 /* delete tooltip control */
1549 if (infoPtr->hwndToolTip)
1550 DestroyWindow (infoPtr->hwndToolTip);
1552 Free (infoPtr->tics);
1553 infoPtr->tics = NULL;
1555 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1556 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1557 Free (infoPtr);
1559 return 0;
1563 static LRESULT
1564 TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr)
1566 TRACE("\n");
1567 infoPtr->bFocussed = FALSE;
1568 TRACKBAR_InvalidateAll(infoPtr);
1570 return 0;
1573 static LRESULT
1574 TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, INT x, INT y)
1576 POINT clickPoint;
1578 clickPoint.x = x;
1579 clickPoint.y = y;
1581 SetFocus(infoPtr->hwndSelf);
1583 if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
1584 infoPtr->flags |= TB_DRAG_MODE;
1585 SetCapture (infoPtr->hwndSelf);
1586 TRACKBAR_UpdateToolTip (infoPtr);
1587 TRACKBAR_ActivateToolTip (infoPtr, TRUE);
1588 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1589 } else {
1590 LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
1591 if (dir == 0) return 0;
1592 infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
1593 TRACKBAR_AutoPage (infoPtr, clickPoint);
1594 SetCapture (infoPtr->hwndSelf);
1595 SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
1598 return 0;
1602 static LRESULT
1603 TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr)
1605 if (infoPtr->flags & TB_DRAG_MODE) {
1606 notify_with_scroll (infoPtr, TB_THUMBPOSITION | (infoPtr->lPos<<16));
1607 notify_with_scroll (infoPtr, TB_ENDTRACK);
1608 infoPtr->flags &= ~TB_DRAG_MODE;
1609 ReleaseCapture ();
1610 notify(infoPtr, NM_RELEASEDCAPTURE);
1611 TRACKBAR_ActivateToolTip(infoPtr, FALSE);
1612 TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
1614 if (infoPtr->flags & TB_AUTO_PAGE) {
1615 KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
1616 infoPtr->flags &= ~TB_AUTO_PAGE;
1617 notify_with_scroll (infoPtr, TB_ENDTRACK);
1618 ReleaseCapture ();
1619 notify(infoPtr, NM_RELEASEDCAPTURE);
1622 return 0;
1626 static LRESULT
1627 TRACKBAR_CaptureChanged (const TRACKBAR_INFO *infoPtr)
1629 notify_with_scroll (infoPtr, TB_ENDTRACK);
1630 return 0;
1634 static LRESULT
1635 TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
1637 if (hdc) {
1638 TRACKBAR_Refresh(infoPtr, hdc);
1639 } else {
1640 PAINTSTRUCT ps;
1641 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
1642 TRACKBAR_Refresh (infoPtr, hdc);
1643 EndPaint (infoPtr->hwndSelf, &ps);
1646 return 0;
1650 static LRESULT
1651 TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr)
1653 TRACE("\n");
1654 infoPtr->bFocussed = TRUE;
1655 TRACKBAR_InvalidateAll(infoPtr);
1657 return 0;
1661 static LRESULT
1662 TRACKBAR_Size (TRACKBAR_INFO *infoPtr)
1664 if (infoPtr->dwStyle & TBS_FIXEDLENGTH)
1666 TRACKBAR_CalcChannel(infoPtr);
1667 TRACKBAR_UpdateThumb(infoPtr);
1669 else
1670 TRACKBAR_InitializeThumb(infoPtr);
1671 TRACKBAR_AlignBuddies (infoPtr);
1672 TRACKBAR_InvalidateAll(infoPtr);
1674 return 0;
1677 static LRESULT
1678 TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType,
1679 const STYLESTRUCT *lpss)
1681 if (wStyleType != GWL_STYLE) return 0;
1683 infoPtr->dwStyle = lpss->styleNew;
1685 return 0;
1688 static LRESULT
1689 TRACKBAR_Timer (TRACKBAR_INFO *infoPtr)
1691 if (infoPtr->flags & TB_AUTO_PAGE) {
1692 POINT pt;
1693 if (GetCursorPos(&pt))
1694 if (ScreenToClient(infoPtr->hwndSelf, &pt))
1695 TRACKBAR_AutoPage(infoPtr, pt);
1697 return 0;
1701 /* update theme after a WM_THEMECHANGED message */
1702 static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr)
1704 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1705 CloseThemeData (theme);
1706 OpenThemeData (infoPtr->hwndSelf, themeClass);
1707 return 0;
1711 static LRESULT
1712 TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y)
1714 INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x;
1715 LONG dragPos, oldPos = infoPtr->lPos;
1717 TRACE("(x=%d. y=%d)\n", x, y);
1719 if (infoPtr->flags & TB_AUTO_PAGE) {
1720 POINT pt;
1721 pt.x = x;
1722 pt.y = y;
1723 TRACKBAR_AutoPage (infoPtr, pt);
1724 return TRUE;
1727 if (!(infoPtr->flags & TB_DRAG_MODE))
1729 if (GetWindowTheme (infoPtr->hwndSelf))
1731 DWORD oldFlags = infoPtr->flags;
1732 POINT pt;
1733 pt.x = x;
1734 pt.y = y;
1735 if (PtInRect (&infoPtr->rcThumb, pt))
1737 TRACKMOUSEEVENT tme;
1738 tme.cbSize = sizeof( tme );
1739 tme.dwFlags = TME_LEAVE;
1740 tme.hwndTrack = infoPtr->hwndSelf;
1741 TrackMouseEvent( &tme );
1742 infoPtr->flags |= TB_THUMB_HOT;
1744 else
1746 TRACKMOUSEEVENT tme;
1747 tme.cbSize = sizeof( tme );
1748 tme.dwFlags = TME_CANCEL;
1749 tme.hwndTrack = infoPtr->hwndSelf;
1750 TrackMouseEvent( &tme );
1751 infoPtr->flags &= ~TB_THUMB_HOT;
1753 if (oldFlags != infoPtr->flags) InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
1755 return TRUE;
1758 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace);
1760 if (dragPos == oldPos) return TRUE;
1762 infoPtr->lPos = dragPos;
1763 TRACKBAR_UpdateThumb (infoPtr);
1765 notify_with_scroll (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
1767 TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
1768 UpdateWindow (infoPtr->hwndSelf);
1770 return TRUE;
1773 static BOOL
1774 TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey)
1776 BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT;
1777 BOOL vert = infoPtr->dwStyle & TBS_VERT;
1778 LONG pos = infoPtr->lPos;
1780 TRACE("%x\n", nVirtKey);
1782 switch (nVirtKey) {
1783 case VK_UP:
1784 if (!vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1785 else TRACKBAR_LineUp(infoPtr);
1786 break;
1787 case VK_LEFT:
1788 if (vert && downIsLeft) TRACKBAR_LineDown(infoPtr);
1789 else TRACKBAR_LineUp(infoPtr);
1790 break;
1791 case VK_DOWN:
1792 if (!vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1793 else TRACKBAR_LineDown(infoPtr);
1794 break;
1795 case VK_RIGHT:
1796 if (vert && downIsLeft) TRACKBAR_LineUp(infoPtr);
1797 else TRACKBAR_LineDown(infoPtr);
1798 break;
1799 case VK_NEXT:
1800 if (!vert && downIsLeft) TRACKBAR_PageUp(infoPtr);
1801 else TRACKBAR_PageDown(infoPtr);
1802 break;
1803 case VK_PRIOR:
1804 if (!vert && downIsLeft) TRACKBAR_PageDown(infoPtr);
1805 else TRACKBAR_PageUp(infoPtr);
1806 break;
1807 case VK_HOME:
1808 if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
1809 infoPtr->lPos = infoPtr->lRangeMin;
1810 notify_with_scroll (infoPtr, TB_TOP);
1811 break;
1812 case VK_END:
1813 if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
1814 infoPtr->lPos = infoPtr->lRangeMax;
1815 notify_with_scroll (infoPtr, TB_BOTTOM);
1816 break;
1819 if (pos != infoPtr->lPos) {
1820 infoPtr->flags |=TB_THUMBPOSCHANGED;
1821 TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
1824 return TRUE;
1828 static inline BOOL
1829 TRACKBAR_KeyUp (const TRACKBAR_INFO *infoPtr, INT nVirtKey)
1831 switch (nVirtKey) {
1832 case VK_LEFT:
1833 case VK_UP:
1834 case VK_RIGHT:
1835 case VK_DOWN:
1836 case VK_NEXT:
1837 case VK_PRIOR:
1838 case VK_HOME:
1839 case VK_END:
1840 notify_with_scroll (infoPtr, TB_ENDTRACK);
1842 return TRUE;
1846 static LRESULT
1847 TRACKBAR_Enable (TRACKBAR_INFO *infoPtr, BOOL enable)
1849 if (enable)
1850 infoPtr->dwStyle &= ~WS_DISABLED;
1851 else
1852 infoPtr->dwStyle |= WS_DISABLED;
1854 InvalidateRect(infoPtr->hwndSelf, &infoPtr->rcThumb, TRUE);
1856 return 1;
1859 static LRESULT WINAPI
1860 TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1862 TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongPtrW (hwnd, 0);
1864 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1866 if (!infoPtr && (uMsg != WM_CREATE))
1867 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1869 switch (uMsg)
1871 case TBM_CLEARSEL:
1872 return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
1874 case TBM_CLEARTICS:
1875 return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
1877 case TBM_GETBUDDY:
1878 return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
1880 case TBM_GETCHANNELRECT:
1881 return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
1883 case TBM_GETLINESIZE:
1884 return infoPtr->lLineSize;
1886 case TBM_GETNUMTICS:
1887 return TRACKBAR_GetNumTics (infoPtr);
1889 case TBM_GETPAGESIZE:
1890 return infoPtr->lPageSize;
1892 case TBM_GETPOS:
1893 return infoPtr->lPos;
1895 case TBM_GETPTICS:
1896 return (LRESULT)infoPtr->tics;
1898 case TBM_GETRANGEMAX:
1899 return infoPtr->lRangeMax;
1901 case TBM_GETRANGEMIN:
1902 return infoPtr->lRangeMin;
1904 case TBM_GETSELEND:
1905 return infoPtr->lSelMax;
1907 case TBM_GETSELSTART:
1908 return infoPtr->lSelMin;
1910 case TBM_GETTHUMBLENGTH:
1911 return infoPtr->uThumbLen;
1913 case TBM_GETTHUMBRECT:
1914 return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
1916 case TBM_GETTIC:
1917 return TRACKBAR_GetTic (infoPtr, (INT)wParam);
1919 case TBM_GETTICPOS:
1920 return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
1922 case TBM_GETTOOLTIPS:
1923 return (LRESULT)infoPtr->hwndToolTip;
1925 case TBM_GETUNICODEFORMAT:
1926 return infoPtr->bUnicode;
1928 case TBM_SETBUDDY:
1929 return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
1931 case TBM_SETLINESIZE:
1932 return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
1934 case TBM_SETPAGESIZE:
1935 return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
1937 case TBM_SETPOS:
1938 return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
1940 case TBM_SETRANGE:
1941 return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
1943 case TBM_SETRANGEMAX:
1944 return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
1946 case TBM_SETRANGEMIN:
1947 return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
1949 case TBM_SETSEL:
1950 return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
1952 case TBM_SETSELEND:
1953 return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
1955 case TBM_SETSELSTART:
1956 return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
1958 case TBM_SETTHUMBLENGTH:
1959 return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
1961 case TBM_SETTIC:
1962 return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
1964 case TBM_SETTICFREQ:
1965 return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
1967 case TBM_SETTIPSIDE:
1968 return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
1970 case TBM_SETTOOLTIPS:
1971 return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
1973 case TBM_SETUNICODEFORMAT:
1974 return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1977 case WM_CAPTURECHANGED:
1978 return TRACKBAR_CaptureChanged (infoPtr);
1980 case WM_CREATE:
1981 return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
1983 case WM_DESTROY:
1984 return TRACKBAR_Destroy (infoPtr);
1986 case WM_ENABLE:
1987 return TRACKBAR_Enable (infoPtr, (BOOL)wParam);
1989 case WM_ERASEBKGND:
1990 return 0;
1992 case WM_GETDLGCODE:
1993 return DLGC_WANTARROWS;
1995 case WM_KEYDOWN:
1996 return TRACKBAR_KeyDown (infoPtr, (INT)wParam);
1998 case WM_KEYUP:
1999 return TRACKBAR_KeyUp (infoPtr, (INT)wParam);
2001 case WM_KILLFOCUS:
2002 return TRACKBAR_KillFocus (infoPtr);
2004 case WM_LBUTTONDOWN:
2005 return TRACKBAR_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2007 case WM_LBUTTONUP:
2008 return TRACKBAR_LButtonUp (infoPtr);
2010 case WM_MOUSELEAVE:
2011 infoPtr->flags &= ~TB_THUMB_HOT;
2012 InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
2013 return 0;
2015 case WM_MOUSEMOVE:
2016 return TRACKBAR_MouseMove (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2018 case WM_PRINTCLIENT:
2019 case WM_PAINT:
2020 return TRACKBAR_Paint (infoPtr, (HDC)wParam);
2022 case WM_SETFOCUS:
2023 return TRACKBAR_SetFocus (infoPtr);
2025 case WM_SIZE:
2026 return TRACKBAR_Size (infoPtr);
2028 case WM_STYLECHANGED:
2029 return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2031 case WM_THEMECHANGED:
2032 return theme_changed (infoPtr);
2034 case WM_TIMER:
2035 return TRACKBAR_Timer (infoPtr);
2037 case WM_WININICHANGE:
2038 return TRACKBAR_InitializeThumb (infoPtr);
2040 default:
2041 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2042 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2043 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2048 void TRACKBAR_Register (void)
2050 WNDCLASSW wndClass;
2052 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2053 wndClass.style = CS_GLOBALCLASS;
2054 wndClass.lpfnWndProc = TRACKBAR_WindowProc;
2055 wndClass.cbClsExtra = 0;
2056 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
2057 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2058 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2059 wndClass.lpszClassName = TRACKBAR_CLASSW;
2061 RegisterClassW (&wndClass);
2065 void TRACKBAR_Unregister (void)
2067 UnregisterClassW (TRACKBAR_CLASSW, NULL);