4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1998, 1999 Alex Priem
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
44 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(trackbar
);
77 #define TB_REFRESH_TIMER 1
78 #define TB_REFRESH_DELAY 500
80 #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
82 /* Used by TRACKBAR_Refresh to find out which parts of the control
83 need to be recalculated */
85 #define TB_THUMBPOSCHANGED 1
86 #define TB_THUMBSIZECHANGED 2
87 #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
88 #define TB_SELECTIONCHANGED 4
89 #define TB_DRAG_MODE 8 /* we're dragging the slider */
90 #define TB_AUTO_PAGE_LEFT 16
91 #define TB_AUTO_PAGE_RIGHT 32
92 #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
94 /* helper defines for TRACKBAR_DrawTic */
96 #define TIC_SELECTIONMARKMAX 0x80
97 #define TIC_SELECTIONMARKMIN 0x100
98 #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
101 notify_customdraw(TRACKBAR_INFO
*infoPtr
, NMCUSTOMDRAW
*pnmcd
, int stage
)
103 pnmcd
->dwDrawStage
= stage
;
104 return SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
105 pnmcd
->hdr
.idFrom
, (LPARAM
)pnmcd
);
108 static LRESULT
notify_hdr(TRACKBAR_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
112 TRACE("(code=%d)\n", code
);
114 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
115 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
117 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
118 (WPARAM
)pnmh
->idFrom
, (LPARAM
)pnmh
);
120 TRACE(" <= %ld\n", result
);
125 static inline int notify(TRACKBAR_INFO
*infoPtr
, INT code
)
128 return notify_hdr(infoPtr
, code
, &nmh
);
132 notify_with_scroll (TRACKBAR_INFO
*infoPtr
, UINT code
)
134 BOOL bVert
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_VERT
;
138 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
,
139 bVert
? WM_VSCROLL
: WM_HSCROLL
,
140 (WPARAM
)code
, (LPARAM
)infoPtr
->hwndSelf
);
143 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO
*infoPtr
)
147 if (infoPtr
->uTicFreq
&& infoPtr
->lRangeMax
>= infoPtr
->lRangeMin
)
148 nrTics
=(infoPtr
->lRangeMax
- infoPtr
->lRangeMin
)/infoPtr
->uTicFreq
;
151 Free (infoPtr
->tics
);
152 infoPtr
->tics
= NULL
;
153 infoPtr
->uNumTics
= 0;
157 if (nrTics
!= infoPtr
->uNumTics
) {
158 infoPtr
->tics
=ReAlloc (infoPtr
->tics
,
159 (nrTics
+1)*sizeof (DWORD
));
160 if (!infoPtr
->tics
) {
161 infoPtr
->uNumTics
= 0;
162 notify(infoPtr
, NM_OUTOFMEMORY
);
165 infoPtr
->uNumTics
= nrTics
;
168 tic
= infoPtr
->lRangeMin
+ infoPtr
->uTicFreq
;
169 for (i
= 0; i
< nrTics
; i
++, tic
+= infoPtr
->uTicFreq
)
170 infoPtr
->tics
[i
] = tic
;
173 /* converts from physical (mouse) position to logical position
174 (in range of trackbar) */
177 TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO
*infoPtr
, int place
,
180 double range
, width
, pos
, offsetthumb
;
182 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
184 offsetthumb
= (infoPtr
->rcThumb
.bottom
- infoPtr
->rcThumb
.top
)/2;
185 width
= infoPtr
->rcChannel
.bottom
- infoPtr
->rcChannel
.top
- (offsetthumb
* 2) - 1;
186 pos
= (range
*(place
- infoPtr
->rcChannel
.top
- offsetthumb
)) / width
;
188 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
189 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- (offsetthumb
* 2) - 1;
190 pos
= (range
*(place
- infoPtr
->rcChannel
.left
- offsetthumb
)) / width
;
192 pos
+= infoPtr
->lRangeMin
;
193 if (pos
> infoPtr
->lRangeMax
)
194 pos
= infoPtr
->lRangeMax
;
195 else if (pos
< infoPtr
->lRangeMin
)
196 pos
= infoPtr
->lRangeMin
;
198 TRACE("%.2f\n", pos
);
199 return (LONG
)(pos
+ 0.5);
203 /* return: 0> prev, 0 none, >0 next */
205 TRACKBAR_GetAutoPageDirection (TRACKBAR_INFO
*infoPtr
, POINT clickPoint
)
207 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
210 if (dwStyle
& TBS_VERT
) {
211 pageRect
.top
= infoPtr
->rcChannel
.top
;
212 pageRect
.bottom
= infoPtr
->rcChannel
.bottom
;
213 pageRect
.left
= infoPtr
->rcThumb
.left
;
214 pageRect
.right
= infoPtr
->rcThumb
.right
;
216 pageRect
.top
= infoPtr
->rcThumb
.top
;
217 pageRect
.bottom
= infoPtr
->rcThumb
.bottom
;
218 pageRect
.left
= infoPtr
->rcChannel
.left
;
219 pageRect
.right
= infoPtr
->rcChannel
.right
;
223 if (PtInRect(&pageRect
, clickPoint
))
225 int clickPlace
= (dwStyle
& TBS_VERT
) ? clickPoint
.y
: clickPoint
.x
;
227 LONG clickPos
= TRACKBAR_ConvertPlaceToPosition(infoPtr
, clickPlace
,
229 return clickPos
- infoPtr
->lPos
;
236 TRACKBAR_PageDown (TRACKBAR_INFO
*infoPtr
)
238 if (infoPtr
->lPos
== infoPtr
->lRangeMax
) return;
240 infoPtr
->lPos
+= infoPtr
->lPageSize
;
241 if (infoPtr
->lPos
> infoPtr
->lRangeMax
)
242 infoPtr
->lPos
= infoPtr
->lRangeMax
;
243 notify_with_scroll (infoPtr
, TB_PAGEDOWN
);
248 TRACKBAR_PageUp (TRACKBAR_INFO
*infoPtr
)
250 if (infoPtr
->lPos
== infoPtr
->lRangeMin
) return;
252 infoPtr
->lPos
-= infoPtr
->lPageSize
;
253 if (infoPtr
->lPos
< infoPtr
->lRangeMin
)
254 infoPtr
->lPos
= infoPtr
->lRangeMin
;
255 notify_with_scroll (infoPtr
, TB_PAGEUP
);
258 static void inline TRACKBAR_LineUp(TRACKBAR_INFO
*infoPtr
)
260 if (infoPtr
->lPos
== infoPtr
->lRangeMin
) return;
261 infoPtr
->lPos
-= infoPtr
->lLineSize
;
262 if (infoPtr
->lPos
< infoPtr
->lRangeMin
)
263 infoPtr
->lPos
= infoPtr
->lRangeMin
;
264 notify_with_scroll (infoPtr
, TB_LINEUP
);
267 static void inline TRACKBAR_LineDown(TRACKBAR_INFO
*infoPtr
)
269 if (infoPtr
->lPos
== infoPtr
->lRangeMax
) return;
270 infoPtr
->lPos
+= infoPtr
->lLineSize
;
271 if (infoPtr
->lPos
> infoPtr
->lRangeMax
)
272 infoPtr
->lPos
= infoPtr
->lRangeMax
;
273 notify_with_scroll (infoPtr
, TB_LINEDOWN
);
277 TRACKBAR_CalcChannel (TRACKBAR_INFO
*infoPtr
)
279 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
280 INT cyChannel
, offsetthumb
, offsetedge
;
281 RECT lpRect
, *channel
= & infoPtr
->rcChannel
;
283 GetClientRect (infoPtr
->hwndSelf
, &lpRect
);
285 offsetthumb
= infoPtr
->uThumbLen
/ 4;
286 offsetedge
= offsetthumb
+ 3;
287 cyChannel
= (dwStyle
& TBS_ENABLESELRANGE
) ? offsetthumb
*3 : 4;
288 if (dwStyle
& TBS_VERT
) {
289 channel
->top
= lpRect
.top
+ offsetedge
;
290 channel
->bottom
= lpRect
.bottom
- offsetedge
;
291 if (dwStyle
& TBS_ENABLESELRANGE
)
292 channel
->left
= lpRect
.left
+ ((infoPtr
->uThumbLen
- cyChannel
+ 2) / 2);
294 channel
->left
= lpRect
.left
+ (infoPtr
->uThumbLen
/ 2) - 1;
295 if (dwStyle
& TBS_BOTH
) {
296 if (dwStyle
& TBS_NOTICKS
)
301 else if (dwStyle
& TBS_TOP
) {
302 if (dwStyle
& TBS_NOTICKS
)
307 channel
->right
= channel
->left
+ cyChannel
;
309 channel
->left
= lpRect
.left
+ offsetedge
;
310 channel
->right
= lpRect
.right
- offsetedge
;
311 if (dwStyle
& TBS_ENABLESELRANGE
)
312 channel
->top
= lpRect
.top
+ ((infoPtr
->uThumbLen
- cyChannel
+ 2) / 2);
314 channel
->top
= lpRect
.top
+ (infoPtr
->uThumbLen
/ 2) - 1;
315 if (dwStyle
& TBS_BOTH
) {
316 if (dwStyle
& TBS_NOTICKS
)
321 else if (dwStyle
& TBS_TOP
) {
322 if (dwStyle
& TBS_NOTICKS
)
327 channel
->bottom
= channel
->top
+ cyChannel
;
332 TRACKBAR_CalcThumb (TRACKBAR_INFO
*infoPtr
, LONG lPos
, RECT
*thumb
)
334 int range
, width
, height
, thumbwidth
;
335 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
338 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
339 thumbwidth
= (infoPtr
->uThumbLen
/ 2) | 1;
341 if (!range
) range
= 1;
343 GetClientRect(infoPtr
->hwndSelf
, &lpRect
);
344 if (dwStyle
& TBS_VERT
)
346 height
= infoPtr
->rcChannel
.bottom
- infoPtr
->rcChannel
.top
- thumbwidth
;
348 if ((dwStyle
& (TBS_BOTH
| TBS_LEFT
)) && !(dwStyle
& TBS_NOTICKS
))
352 thumb
->right
= thumb
->left
+ infoPtr
->uThumbLen
;
353 thumb
->top
= infoPtr
->rcChannel
.top
+
354 (height
*(lPos
- infoPtr
->lRangeMin
))/range
;
355 thumb
->bottom
= thumb
->top
+ thumbwidth
;
359 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- thumbwidth
;
361 thumb
->left
= infoPtr
->rcChannel
.left
+
362 (width
*(lPos
- infoPtr
->lRangeMin
))/range
;
363 thumb
->right
= thumb
->left
+ thumbwidth
;
364 if ((dwStyle
& (TBS_BOTH
| TBS_TOP
)) && !(dwStyle
& TBS_NOTICKS
))
368 thumb
->bottom
= thumb
->top
+ infoPtr
->uThumbLen
;
373 TRACKBAR_UpdateThumb (TRACKBAR_INFO
*infoPtr
)
375 TRACKBAR_CalcThumb(infoPtr
, infoPtr
->lPos
, &infoPtr
->rcThumb
);
379 TRACKBAR_InvalidateAll(TRACKBAR_INFO
* infoPtr
)
381 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
385 TRACKBAR_InvalidateThumb (TRACKBAR_INFO
*infoPtr
, LONG thumbPos
)
389 TRACKBAR_CalcThumb(infoPtr
, thumbPos
, &rcThumb
);
390 InflateRect(&rcThumb
, 1, 1);
391 InvalidateRect(infoPtr
->hwndSelf
, &rcThumb
, FALSE
);
395 TRACKBAR_InvalidateThumbMove (TRACKBAR_INFO
*infoPtr
, LONG oldPos
, LONG newPos
)
397 TRACKBAR_InvalidateThumb (infoPtr
, oldPos
);
398 if (newPos
!= oldPos
)
399 TRACKBAR_InvalidateThumb (infoPtr
, newPos
);
403 TRACKBAR_HasSelection (TRACKBAR_INFO
*infoPtr
)
405 return infoPtr
->lSelMin
!= infoPtr
->lSelMax
;
409 TRACKBAR_CalcSelection (TRACKBAR_INFO
*infoPtr
)
411 RECT
*selection
= &infoPtr
->rcSelection
;
412 int range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
413 int offsetthumb
, height
, width
;
416 SetRectEmpty (selection
);
418 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_VERT
) {
419 offsetthumb
= (infoPtr
->rcThumb
.bottom
- infoPtr
->rcThumb
.top
)/2;
420 height
= infoPtr
->rcChannel
.bottom
- infoPtr
->rcChannel
.top
- offsetthumb
*2;
421 selection
->top
= infoPtr
->rcChannel
.top
+ offsetthumb
+
422 (height
*infoPtr
->lSelMin
)/range
;
423 selection
->bottom
= infoPtr
->rcChannel
.top
+ offsetthumb
+
424 (height
*infoPtr
->lSelMax
)/range
;
425 selection
->left
= infoPtr
->rcChannel
.left
+ 3;
426 selection
->right
= infoPtr
->rcChannel
.right
- 3;
428 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
429 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- offsetthumb
*2;
430 selection
->left
= infoPtr
->rcChannel
.left
+ offsetthumb
+
431 (width
*infoPtr
->lSelMin
)/range
;
432 selection
->right
= infoPtr
->rcChannel
.left
+ offsetthumb
+
433 (width
*infoPtr
->lSelMax
)/range
;
434 selection
->top
= infoPtr
->rcChannel
.top
+ 3;
435 selection
->bottom
= infoPtr
->rcChannel
.bottom
- 3;
439 TRACE("selection[left=%ld, top=%ld, right=%ld, bottom=%ld]\n",
440 selection
->left
, selection
->top
, selection
->right
, selection
->bottom
);
444 TRACKBAR_AutoPage (TRACKBAR_INFO
*infoPtr
, POINT clickPoint
)
446 LONG dir
= TRACKBAR_GetAutoPageDirection(infoPtr
, clickPoint
);
447 LONG prevPos
= infoPtr
->lPos
;
449 TRACE("x=%ld, y=%ld, dir=%ld\n", clickPoint
.x
, clickPoint
.y
, dir
);
451 if (dir
> 0 && (infoPtr
->flags
& TB_AUTO_PAGE_RIGHT
))
452 TRACKBAR_PageDown(infoPtr
);
453 else if (dir
< 0 && (infoPtr
->flags
& TB_AUTO_PAGE_LEFT
))
454 TRACKBAR_PageUp(infoPtr
);
457 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
458 TRACKBAR_InvalidateThumbMove (infoPtr
, prevPos
, infoPtr
->lPos
);
463 /* Trackbar drawing code. I like my spaghetti done milanese. */
466 TRACKBAR_DrawChannel (TRACKBAR_INFO
*infoPtr
, HDC hdc
, DWORD dwStyle
)
468 RECT rcChannel
= infoPtr
->rcChannel
;
470 DrawEdge (hdc
, &rcChannel
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
471 if (dwStyle
& TBS_ENABLESELRANGE
) { /* fill the channel */
472 FillRect (hdc
, &rcChannel
, GetStockObject(WHITE_BRUSH
));
473 if (TRACKBAR_HasSelection(infoPtr
))
474 FillRect (hdc
, &infoPtr
->rcSelection
, GetSysColorBrush(COLOR_HIGHLIGHT
));
479 TRACKBAR_DrawOneTic (TRACKBAR_INFO
*infoPtr
, HDC hdc
, LONG ticPos
, int flags
)
481 int x
, y
, ox
, oy
, range
, side
, indent
= 0, len
= 3;
485 if (flags
& TBS_VERT
) {
486 offsetthumb
= (infoPtr
->rcThumb
.bottom
- infoPtr
->rcThumb
.top
)/2;
487 rcTics
.left
= infoPtr
->rcThumb
.left
- 2;
488 rcTics
.right
= infoPtr
->rcThumb
.right
+ 2;
489 rcTics
.top
= infoPtr
->rcChannel
.top
+ offsetthumb
+ 1;
490 rcTics
.bottom
= infoPtr
->rcChannel
.bottom
- offsetthumb
;
492 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
493 rcTics
.left
= infoPtr
->rcChannel
.left
+ offsetthumb
+ 1;
494 rcTics
.right
= infoPtr
->rcChannel
.right
- offsetthumb
;
495 rcTics
.top
= infoPtr
->rcThumb
.top
- 2;
496 rcTics
.bottom
= infoPtr
->rcThumb
.bottom
+ 2;
499 if (flags
& (TBS_TOP
| TBS_LEFT
)) {
509 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
511 range
= 1; /* to avoid division by zero */
513 if (flags
& TIC_SELECTIONMARK
) {
514 indent
= (flags
& TIC_SELECTIONMARKMIN
) ? -1 : 1;
515 } else if (flags
& TIC_EDGE
) {
519 if (flags
& TBS_VERT
) {
520 int height
= rcTics
.bottom
- rcTics
.top
;
521 y
= rcTics
.top
+ (height
*(ticPos
- infoPtr
->lRangeMin
))/range
;
523 int width
= rcTics
.right
- rcTics
.left
;
524 x
= rcTics
.left
+ (width
*(ticPos
- infoPtr
->lRangeMin
))/range
;
529 MoveToEx(hdc
, x
, y
, 0);
530 if (flags
& TBS_VERT
) x
+= len
* side
;
531 else y
+= len
* side
;
534 if (flags
& TIC_SELECTIONMARK
) {
535 if (flags
& TBS_VERT
) {
540 MoveToEx(hdc
, x
, y
, 0);
541 if (flags
& TBS_VERT
) {
554 TRACKBAR_DrawTic (TRACKBAR_INFO
*infoPtr
, HDC hdc
, LONG ticPos
, int flags
)
556 if ((flags
& (TBS_LEFT
| TBS_TOP
)) || (flags
& TBS_BOTH
))
557 TRACKBAR_DrawOneTic (infoPtr
, hdc
, ticPos
, flags
| TBS_LEFT
);
559 if (!(flags
& (TBS_LEFT
| TBS_TOP
)) || (flags
& TBS_BOTH
))
560 TRACKBAR_DrawOneTic (infoPtr
, hdc
, ticPos
, flags
& ~TBS_LEFT
);
564 TRACKBAR_DrawTics (TRACKBAR_INFO
*infoPtr
, HDC hdc
, DWORD dwStyle
)
567 int ticFlags
= dwStyle
& 0x0f;
568 LOGPEN ticPen
= { PS_SOLID
, {1, 0}, GetSysColor (COLOR_3DDKSHADOW
) };
569 HPEN hOldPen
, hTicPen
;
571 /* create the pen to draw the tics with */
572 hTicPen
= CreatePenIndirect(&ticPen
);
573 hOldPen
= hTicPen
? SelectObject(hdc
, hTicPen
) : 0;
575 /* actually draw the tics */
576 for (i
=0; i
<infoPtr
->uNumTics
; i
++)
577 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->tics
[i
], ticFlags
);
579 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lRangeMin
, ticFlags
| TIC_EDGE
);
580 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lRangeMax
, ticFlags
| TIC_EDGE
);
582 if ((dwStyle
& TBS_ENABLESELRANGE
) && TRACKBAR_HasSelection(infoPtr
)) {
583 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lSelMin
,
584 ticFlags
| TIC_SELECTIONMARKMIN
);
585 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lSelMax
,
586 ticFlags
| TIC_SELECTIONMARKMAX
);
589 /* clean up the pen, if we created one */
591 SelectObject(hdc
, hOldPen
);
592 DeleteObject(hTicPen
);
597 TRACKBAR_DrawThumb(TRACKBAR_INFO
*infoPtr
, HDC hdc
, DWORD dwStyle
)
601 RECT thumb
= infoPtr
->rcThumb
;
608 fillClr
= infoPtr
->flags
& TB_DRAG_MODE
? COLOR_BTNHILIGHT
: COLOR_BTNFACE
;
609 oldbr
= SelectObject (hdc
, GetSysColorBrush(fillClr
));
610 SetPolyFillMode (hdc
, WINDING
);
612 if (dwStyle
& TBS_BOTH
)
614 points
[0].x
=thumb
.right
;
615 points
[0].y
=thumb
.top
;
616 points
[1].x
=thumb
.right
;
617 points
[1].y
=thumb
.bottom
;
618 points
[2].x
=thumb
.left
;
619 points
[2].y
=thumb
.bottom
;
620 points
[3].x
=thumb
.left
;
621 points
[3].y
=thumb
.top
;
622 points
[4].x
=points
[0].x
;
623 points
[4].y
=points
[0].y
;
629 if (dwStyle
& TBS_VERT
)
631 PointDepth
= (thumb
.bottom
- thumb
.top
) / 2;
632 if (dwStyle
& TBS_LEFT
)
634 points
[0].x
=thumb
.right
;
635 points
[0].y
=thumb
.top
;
636 points
[1].x
=thumb
.right
;
637 points
[1].y
=thumb
.bottom
;
638 points
[2].x
=thumb
.left
+ PointDepth
;
639 points
[2].y
=thumb
.bottom
;
640 points
[3].x
=thumb
.left
;
641 points
[3].y
=(thumb
.bottom
- thumb
.top
) / 2 + thumb
.top
+ 1;
642 points
[4].x
=thumb
.left
+ PointDepth
;
643 points
[4].y
=thumb
.top
;
644 points
[5].x
=points
[0].x
;
645 points
[5].y
=points
[0].y
;
650 points
[0].x
=thumb
.right
;
651 points
[0].y
=(thumb
.bottom
- thumb
.top
) / 2 + thumb
.top
+ 1;
652 points
[1].x
=thumb
.right
- PointDepth
;
653 points
[1].y
=thumb
.bottom
;
654 points
[2].x
=thumb
.left
;
655 points
[2].y
=thumb
.bottom
;
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
;
666 PointDepth
= (thumb
.right
- thumb
.left
) / 2;
667 if (dwStyle
& TBS_TOP
)
669 points
[0].x
=(thumb
.right
- thumb
.left
) / 2 + thumb
.left
+ 1;
670 points
[0].y
=thumb
.top
;
671 points
[1].x
=thumb
.right
;
672 points
[1].y
=thumb
.top
+ PointDepth
;
673 points
[2].x
=thumb
.right
;
674 points
[2].y
=thumb
.bottom
;
675 points
[3].x
=thumb
.left
;
676 points
[3].y
=thumb
.bottom
;
677 points
[4].x
=thumb
.left
;
678 points
[4].y
=thumb
.top
+ PointDepth
;
679 points
[5].x
=points
[0].x
;
680 points
[5].y
=points
[0].y
;
685 points
[0].x
=thumb
.right
;
686 points
[0].y
=thumb
.top
;
687 points
[1].x
=thumb
.right
;
688 points
[1].y
=thumb
.bottom
- PointDepth
;
689 points
[2].x
=(thumb
.right
- thumb
.left
) / 2 + thumb
.left
+ 1;
690 points
[2].y
=thumb
.bottom
;
691 points
[3].x
=thumb
.left
;
692 points
[3].y
=thumb
.bottom
- PointDepth
;
693 points
[4].x
=thumb
.left
;
694 points
[4].y
=thumb
.top
;
695 points
[5].x
=points
[0].x
;
696 points
[5].y
=points
[0].y
;
702 /* Draw the thumb now */
703 Polygon (hdc
, points
, PointCount
);
704 oldpen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
705 Polyline(hdc
,points
, BlackUntil
);
706 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
707 Polyline(hdc
, &points
[BlackUntil
-1], PointCount
+1-BlackUntil
);
708 SelectObject(hdc
, oldpen
);
709 SelectObject(hdc
, oldbr
);
714 TRACKBAR_ActivateToolTip (TRACKBAR_INFO
*infoPtr
, BOOL fShow
)
718 if (!infoPtr
->hwndToolTip
) return;
720 ZeroMemory(&ti
, sizeof(ti
));
721 ti
.cbSize
= sizeof(ti
);
722 ti
.hwnd
= infoPtr
->hwndSelf
;
724 SendMessageW (infoPtr
->hwndToolTip
, TTM_TRACKACTIVATE
, fShow
, (LPARAM
)&ti
);
729 TRACKBAR_UpdateToolTip (TRACKBAR_INFO
*infoPtr
)
731 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
733 static const WCHAR fmt
[] = { '%', 'l', 'd', 0 };
739 if (!infoPtr
->hwndToolTip
) return;
741 ZeroMemory(&ti
, sizeof(ti
));
742 ti
.cbSize
= sizeof(ti
);
743 ti
.hwnd
= infoPtr
->hwndSelf
;
744 ti
.uFlags
= TTF_IDISHWND
| TTF_TRACK
| TTF_ABSOLUTE
;
746 wsprintfW (buf
, fmt
, infoPtr
->lPos
);
748 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
750 GetClientRect (infoPtr
->hwndSelf
, &rcClient
);
751 size
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETBUBBLESIZE
, 0, (LPARAM
)&ti
);
752 if (dwStyle
& TBS_VERT
) {
753 if (infoPtr
->fLocation
== TBTS_LEFT
)
754 pt
.x
= 0 - LOWORD(size
) - TOOLTIP_OFFSET
;
756 pt
.x
= rcClient
.right
+ TOOLTIP_OFFSET
;
757 pt
.y
= (infoPtr
->rcThumb
.top
+ infoPtr
->rcThumb
.bottom
- HIWORD(size
))/2;
759 if (infoPtr
->fLocation
== TBTS_TOP
)
760 pt
.y
= 0 - HIWORD(size
) - TOOLTIP_OFFSET
;
762 pt
.y
= rcClient
.bottom
+ TOOLTIP_OFFSET
;
763 pt
.x
= (infoPtr
->rcThumb
.left
+ infoPtr
->rcThumb
.right
- LOWORD(size
))/2;
765 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
767 SendMessageW (infoPtr
->hwndToolTip
, TTM_TRACKPOSITION
,
768 0, (LPARAM
)MAKELPARAM(pt
.x
, pt
.y
));
773 TRACKBAR_Refresh (TRACKBAR_INFO
*infoPtr
, HDC hdcDst
)
775 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
778 HBITMAP hOldBmp
= 0, hOffScreenBmp
= 0;
782 if (infoPtr
->flags
& TB_THUMBCHANGED
) {
783 TRACKBAR_UpdateThumb (infoPtr
);
784 if (infoPtr
->flags
& TB_THUMBSIZECHANGED
)
785 TRACKBAR_CalcChannel (infoPtr
);
787 if (infoPtr
->flags
& TB_SELECTIONCHANGED
)
788 TRACKBAR_CalcSelection (infoPtr
);
790 if (infoPtr
->flags
& TB_DRAG_MODE
)
791 TRACKBAR_UpdateToolTip (infoPtr
);
793 infoPtr
->flags
&= ~ (TB_THUMBCHANGED
| TB_SELECTIONCHANGED
);
795 GetClientRect (infoPtr
->hwndSelf
, &rcClient
);
797 /* try to render offscreen, if we fail, carrry onscreen */
798 hdc
= CreateCompatibleDC(hdcDst
);
800 hOffScreenBmp
= CreateCompatibleBitmap(hdcDst
, rcClient
.right
, rcClient
.bottom
);
802 hOldBmp
= SelectObject(hdc
, hOffScreenBmp
);
811 ZeroMemory(&nmcd
, sizeof(nmcd
));
812 nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
813 nmcd
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
814 nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
817 /* start the paint cycle */
819 gcdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_PREPAINT
);
820 if (gcdrf
& CDRF_SKIPDEFAULT
) goto cleanup
;
822 /* Erase backbround */
823 if (gcdrf
== CDRF_DODEFAULT
||
824 notify_customdraw(infoPtr
, &nmcd
, CDDS_PREERASE
) != CDRF_SKIPDEFAULT
) {
825 FillRect (hdc
, &rcClient
, GetSysColorBrush(COLOR_BTNFACE
));
826 if (gcdrf
!= CDRF_DODEFAULT
)
827 notify_customdraw(infoPtr
, &nmcd
, CDDS_POSTERASE
);
831 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
832 nmcd
.dwItemSpec
= TBCD_CHANNEL
;
833 nmcd
.uItemState
= CDIS_DEFAULT
;
834 nmcd
.rc
= infoPtr
->rcChannel
;
835 icdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPREPAINT
);
836 } else icdrf
= CDRF_DODEFAULT
;
837 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
838 TRACKBAR_DrawChannel (infoPtr
, hdc
, dwStyle
);
839 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
840 notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPOSTPAINT
);
845 if (!(dwStyle
& TBS_NOTICKS
)) {
846 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
847 nmcd
.dwItemSpec
= TBCD_TICS
;
848 nmcd
.uItemState
= CDIS_DEFAULT
;
850 icdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPREPAINT
);
851 } else icdrf
= CDRF_DODEFAULT
;
852 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
853 TRACKBAR_DrawTics (infoPtr
, hdc
, dwStyle
);
854 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
855 notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPOSTPAINT
);
860 if (!(dwStyle
& TBS_NOTHUMB
)) {
861 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
862 nmcd
.dwItemSpec
= TBCD_THUMB
;
863 nmcd
.uItemState
= infoPtr
->flags
& TB_DRAG_MODE
? CDIS_HOT
: CDIS_DEFAULT
;
864 nmcd
.rc
= infoPtr
->rcThumb
;
865 icdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPREPAINT
);
866 } else icdrf
= CDRF_DODEFAULT
;
867 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
868 TRACKBAR_DrawThumb(infoPtr
, hdc
, dwStyle
);
869 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
870 notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPOSTPAINT
);
874 /* draw focus rectangle */
875 if (infoPtr
->bFocussed
) {
876 DrawFocusRect(hdc
, &rcClient
);
879 /* finish up the painting */
880 if (gcdrf
& CDRF_NOTIFYPOSTPAINT
)
881 notify_customdraw(infoPtr
, &nmcd
, CDDS_POSTPAINT
);
884 /* cleanup, if we rendered offscreen */
886 BitBlt(hdcDst
, 0, 0, rcClient
.right
, rcClient
.bottom
, hdc
, 0, 0, SRCCOPY
);
887 SelectObject(hdc
, hOldBmp
);
888 DeleteObject(hOffScreenBmp
);
895 TRACKBAR_AlignBuddies (TRACKBAR_INFO
*infoPtr
)
897 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
898 HWND hwndParent
= GetParent (infoPtr
->hwndSelf
);
899 RECT rcSelf
, rcBuddy
;
902 GetWindowRect (infoPtr
->hwndSelf
, &rcSelf
);
903 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcSelf
, 2);
905 /* align buddy left or above */
906 if (infoPtr
->hwndBuddyLA
) {
907 GetWindowRect (infoPtr
->hwndBuddyLA
, &rcBuddy
);
908 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcBuddy
, 2);
910 if (dwStyle
& TBS_VERT
) {
911 x
= (infoPtr
->rcChannel
.right
+ infoPtr
->rcChannel
.left
) / 2 -
912 (rcBuddy
.right
- rcBuddy
.left
) / 2 + rcSelf
.left
;
913 y
= rcSelf
.top
- (rcBuddy
.bottom
- rcBuddy
.top
);
916 x
= rcSelf
.left
- (rcBuddy
.right
- rcBuddy
.left
);
917 y
= (infoPtr
->rcChannel
.bottom
+ infoPtr
->rcChannel
.top
) / 2 -
918 (rcBuddy
.bottom
- rcBuddy
.top
) / 2 + rcSelf
.top
;
921 SetWindowPos (infoPtr
->hwndBuddyLA
, 0, x
, y
, 0, 0,
922 SWP_NOZORDER
| SWP_NOSIZE
);
926 /* align buddy right or below */
927 if (infoPtr
->hwndBuddyRB
) {
928 GetWindowRect (infoPtr
->hwndBuddyRB
, &rcBuddy
);
929 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcBuddy
, 2);
931 if (dwStyle
& TBS_VERT
) {
932 x
= (infoPtr
->rcChannel
.right
+ infoPtr
->rcChannel
.left
) / 2 -
933 (rcBuddy
.right
- rcBuddy
.left
) / 2 + rcSelf
.left
;
938 y
= (infoPtr
->rcChannel
.bottom
+ infoPtr
->rcChannel
.top
) / 2 -
939 (rcBuddy
.bottom
- rcBuddy
.top
) / 2 + rcSelf
.top
;
941 SetWindowPos (infoPtr
->hwndBuddyRB
, 0, x
, y
, 0, 0,
942 SWP_NOZORDER
| SWP_NOSIZE
);
948 TRACKBAR_ClearSel (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
)
950 infoPtr
->lSelMin
= 0;
951 infoPtr
->lSelMax
= 0;
952 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
954 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
961 TRACKBAR_ClearTics (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
)
964 Free (infoPtr
->tics
);
965 infoPtr
->tics
= NULL
;
966 infoPtr
->uNumTics
= 0;
969 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
975 static LRESULT
inline
976 TRACKBAR_GetChannelRect (TRACKBAR_INFO
*infoPtr
, LPRECT lprc
)
978 if (lprc
== NULL
) return 0;
980 lprc
->left
= infoPtr
->rcChannel
.left
;
981 lprc
->right
= infoPtr
->rcChannel
.right
;
982 lprc
->bottom
= infoPtr
->rcChannel
.bottom
;
983 lprc
->top
= infoPtr
->rcChannel
.top
;
990 TRACKBAR_GetNumTics (TRACKBAR_INFO
*infoPtr
)
992 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_NOTICKS
)
995 return infoPtr
->uNumTics
+ 2;
999 static int comp_tics(const void *ap
, const void *bp
)
1001 DWORD a
= *((DWORD
*)ap
);
1002 DWORD b
= *((DWORD
*)bp
);
1004 TRACE("(a=%ld, b=%ld)\n", a
, b
);
1005 if (a
< b
) return -1;
1006 if (a
> b
) return 1;
1012 TRACKBAR_GetTic (TRACKBAR_INFO
*infoPtr
, INT iTic
)
1014 if ((iTic
< 0) || (iTic
>= infoPtr
->uNumTics
) || !infoPtr
->tics
)
1017 qsort(infoPtr
->tics
, infoPtr
->uNumTics
, sizeof(DWORD
), comp_tics
);
1018 return infoPtr
->tics
[iTic
];
1023 TRACKBAR_GetTicPos (TRACKBAR_INFO
*infoPtr
, INT iTic
)
1025 LONG range
, width
, pos
, tic
;
1028 if ((iTic
< 0) || (iTic
>= infoPtr
->uNumTics
) || !infoPtr
->tics
)
1031 tic
= TRACKBAR_GetTic (infoPtr
, iTic
);
1032 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
1033 if (range
<= 0) range
= 1;
1034 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
1035 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- offsetthumb
*2;
1036 pos
= infoPtr
->rcChannel
.left
+ offsetthumb
+ (width
* tic
) / range
;
1043 TRACKBAR_SetBuddy (TRACKBAR_INFO
*infoPtr
, BOOL fLocation
, HWND hwndBuddy
)
1048 /* buddy is left or above */
1049 hwndTemp
= infoPtr
->hwndBuddyLA
;
1050 infoPtr
->hwndBuddyLA
= hwndBuddy
;
1053 /* buddy is right or below */
1054 hwndTemp
= infoPtr
->hwndBuddyRB
;
1055 infoPtr
->hwndBuddyRB
= hwndBuddy
;
1058 TRACKBAR_AlignBuddies (infoPtr
);
1065 TRACKBAR_SetLineSize (TRACKBAR_INFO
*infoPtr
, LONG lLineSize
)
1067 LONG lTemp
= infoPtr
->lLineSize
;
1069 infoPtr
->lLineSize
= lLineSize
;
1076 TRACKBAR_SetPageSize (TRACKBAR_INFO
*infoPtr
, LONG lPageSize
)
1078 LONG lTemp
= infoPtr
->lPageSize
;
1080 infoPtr
->lPageSize
= lPageSize
;
1086 static LRESULT
inline
1087 TRACKBAR_SetPos (TRACKBAR_INFO
*infoPtr
, BOOL fPosition
, LONG lPosition
)
1089 LONG oldPos
= infoPtr
->lPos
;
1090 infoPtr
->lPos
= lPosition
;
1092 if (infoPtr
->lPos
< infoPtr
->lRangeMin
)
1093 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1095 if (infoPtr
->lPos
> infoPtr
->lRangeMax
)
1096 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1097 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1099 if (fPosition
) TRACKBAR_InvalidateThumbMove(infoPtr
, oldPos
, lPosition
);
1105 static LRESULT
inline
1106 TRACKBAR_SetRange (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lRange
)
1108 infoPtr
->lRangeMin
= (SHORT
)LOWORD(lRange
);
1109 infoPtr
->lRangeMax
= (SHORT
)HIWORD(lRange
);
1111 if (infoPtr
->lPos
< infoPtr
->lRangeMin
) {
1112 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1113 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1116 if (infoPtr
->lPos
> infoPtr
->lRangeMax
) {
1117 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1118 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1121 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1122 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1124 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1130 static LRESULT
inline
1131 TRACKBAR_SetRangeMax (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lMax
)
1133 infoPtr
->lRangeMax
= lMax
;
1134 if (infoPtr
->lPos
> infoPtr
->lRangeMax
) {
1135 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1136 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1139 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1140 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1142 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1148 static LRESULT
inline
1149 TRACKBAR_SetRangeMin (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lMin
)
1151 infoPtr
->lRangeMin
= lMin
;
1152 if (infoPtr
->lPos
< infoPtr
->lRangeMin
) {
1153 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1154 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1157 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1158 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1160 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1166 static LRESULT
inline
1167 TRACKBAR_SetSel (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lSel
)
1169 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1172 infoPtr
->lSelMin
= (SHORT
)LOWORD(lSel
);
1173 infoPtr
->lSelMax
= (SHORT
)HIWORD(lSel
);
1174 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
1176 if (infoPtr
->lSelMin
< infoPtr
->lRangeMin
)
1177 infoPtr
->lSelMin
= infoPtr
->lRangeMin
;
1178 if (infoPtr
->lSelMax
> infoPtr
->lRangeMax
)
1179 infoPtr
->lSelMax
= infoPtr
->lRangeMax
;
1181 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1187 static LRESULT
inline
1188 TRACKBAR_SetSelEnd (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lEnd
)
1190 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1193 infoPtr
->lSelMax
= lEnd
;
1194 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
1196 if (infoPtr
->lSelMax
> infoPtr
->lRangeMax
)
1197 infoPtr
->lSelMax
= infoPtr
->lRangeMax
;
1199 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1205 static LRESULT
inline
1206 TRACKBAR_SetSelStart (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lStart
)
1208 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1211 infoPtr
->lSelMin
= lStart
;
1212 infoPtr
->flags
|=TB_SELECTIONCHANGED
;
1214 if (infoPtr
->lSelMin
< infoPtr
->lRangeMin
)
1215 infoPtr
->lSelMin
= infoPtr
->lRangeMin
;
1217 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1223 static LRESULT
inline
1224 TRACKBAR_SetThumbLength (TRACKBAR_INFO
*infoPtr
, UINT iLength
)
1226 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_FIXEDLENGTH
) {
1227 infoPtr
->uThumbLen
= iLength
;
1228 infoPtr
->flags
|= TB_THUMBSIZECHANGED
;
1229 InvalidateRect (infoPtr
->hwndSelf
, &infoPtr
->rcThumb
, FALSE
);
1236 static LRESULT
inline
1237 TRACKBAR_SetTic (TRACKBAR_INFO
*infoPtr
, LONG lPos
)
1239 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_AUTOTICKS
)
1242 if ((lPos
< infoPtr
->lRangeMin
) || (lPos
> infoPtr
->lRangeMax
))
1245 TRACE("lPos=%ld\n", lPos
);
1247 infoPtr
->uNumTics
++;
1248 infoPtr
->tics
=ReAlloc( infoPtr
->tics
,
1249 (infoPtr
->uNumTics
)*sizeof (DWORD
));
1250 if (!infoPtr
->tics
) {
1251 infoPtr
->uNumTics
= 0;
1252 notify(infoPtr
, NM_OUTOFMEMORY
);
1255 infoPtr
->tics
[infoPtr
->uNumTics
-1] = lPos
;
1257 TRACKBAR_InvalidateAll(infoPtr
);
1263 static LRESULT
inline
1264 TRACKBAR_SetTicFreq (TRACKBAR_INFO
*infoPtr
, WORD wFreq
)
1266 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_AUTOTICKS
) {
1267 infoPtr
->uTicFreq
= wFreq
;
1268 TRACKBAR_RecalculateTics (infoPtr
);
1269 TRACKBAR_InvalidateAll(infoPtr
);
1277 TRACKBAR_SetTipSide (TRACKBAR_INFO
*infoPtr
, INT fLocation
)
1279 INT fTemp
= infoPtr
->fLocation
;
1281 infoPtr
->fLocation
= fLocation
;
1287 static LRESULT
inline
1288 TRACKBAR_SetToolTips (TRACKBAR_INFO
*infoPtr
, HWND hwndTT
)
1290 infoPtr
->hwndToolTip
= hwndTT
;
1297 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO
*infoPtr
, BOOL fUnicode
)
1299 BOOL bTemp
= infoPtr
->bUnicode
;
1301 infoPtr
->bUnicode
= fUnicode
;
1308 TRACKBAR_InitializeThumb (TRACKBAR_INFO
*infoPtr
)
1310 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1312 int clientWidth
, clientMetric
;
1314 /* initial thumb length */
1315 clientMetric
= (dwStyle
& TBS_ENABLESELRANGE
) ? 23 : 21;
1316 GetClientRect(infoPtr
->hwndSelf
,&rect
);
1317 if (dwStyle
& TBS_VERT
) {
1318 clientWidth
= rect
.right
- rect
.left
;
1320 clientWidth
= rect
.bottom
- rect
.top
;
1322 if (clientWidth
>= clientMetric
)
1323 infoPtr
->uThumbLen
= clientMetric
;
1325 infoPtr
->uThumbLen
= clientWidth
> 9 ? clientWidth
- 6 : 4;
1327 TRACKBAR_CalcChannel (infoPtr
);
1328 TRACKBAR_UpdateThumb (infoPtr
);
1329 infoPtr
->flags
&= ~TB_SELECTIONCHANGED
;
1336 TRACKBAR_Create (HWND hwnd
, LPCREATESTRUCTW lpcs
)
1338 TRACKBAR_INFO
*infoPtr
;
1341 infoPtr
= (TRACKBAR_INFO
*)Alloc (sizeof(TRACKBAR_INFO
));
1342 if (!infoPtr
) return -1;
1343 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1345 /* set default values */
1346 infoPtr
->hwndSelf
= hwnd
;
1347 infoPtr
->lRangeMin
= 0;
1348 infoPtr
->lRangeMax
= 100;
1349 infoPtr
->lLineSize
= 1;
1350 infoPtr
->lPageSize
= 20;
1351 infoPtr
->lSelMin
= 0;
1352 infoPtr
->lSelMax
= 0;
1354 infoPtr
->fLocation
= -1;
1355 infoPtr
->uNumTics
= 0; /* start and end tic are not included in count*/
1356 infoPtr
->uTicFreq
= 1;
1357 infoPtr
->tics
= NULL
;
1358 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1360 TRACKBAR_InitializeThumb (infoPtr
);
1362 dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1364 /* Create tooltip control */
1365 if (dwStyle
& TBS_TOOLTIPS
) {
1367 infoPtr
->hwndToolTip
=
1368 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, 0,
1369 CW_USEDEFAULT
, CW_USEDEFAULT
,
1370 CW_USEDEFAULT
, CW_USEDEFAULT
,
1373 if (infoPtr
->hwndToolTip
) {
1375 ZeroMemory (&ti
, sizeof(ti
));
1376 ti
.cbSize
= sizeof(ti
);
1377 ti
.uFlags
= TTF_IDISHWND
| TTF_TRACK
| TTF_ABSOLUTE
;
1380 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&ti
);
1389 TRACKBAR_Destroy (TRACKBAR_INFO
*infoPtr
)
1391 /* delete tooltip control */
1392 if (infoPtr
->hwndToolTip
)
1393 DestroyWindow (infoPtr
->hwndToolTip
);
1396 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1402 TRACKBAR_KillFocus (TRACKBAR_INFO
*infoPtr
, HWND hwndGetFocus
)
1405 infoPtr
->bFocussed
= FALSE
;
1406 TRACKBAR_InvalidateAll(infoPtr
);
1412 TRACKBAR_LButtonDown (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, INT x
, INT y
)
1419 SetFocus(infoPtr
->hwndSelf
);
1421 if (PtInRect(&infoPtr
->rcThumb
, clickPoint
)) {
1422 infoPtr
->flags
|= TB_DRAG_MODE
;
1423 SetCapture (infoPtr
->hwndSelf
);
1424 TRACKBAR_UpdateToolTip (infoPtr
);
1425 TRACKBAR_ActivateToolTip (infoPtr
, TRUE
);
1426 TRACKBAR_InvalidateThumb(infoPtr
, infoPtr
->lPos
);
1428 LONG dir
= TRACKBAR_GetAutoPageDirection(infoPtr
, clickPoint
);
1429 if (dir
== 0) return 0;
1430 infoPtr
->flags
|= (dir
< 0) ? TB_AUTO_PAGE_LEFT
: TB_AUTO_PAGE_RIGHT
;
1431 TRACKBAR_AutoPage (infoPtr
, clickPoint
);
1432 SetCapture (infoPtr
->hwndSelf
);
1433 SetTimer(infoPtr
->hwndSelf
, TB_REFRESH_TIMER
, TB_REFRESH_DELAY
, 0);
1441 TRACKBAR_LButtonUp (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, INT x
, INT y
)
1443 if (infoPtr
->flags
& TB_DRAG_MODE
) {
1444 notify_with_scroll (infoPtr
, TB_THUMBPOSITION
| (infoPtr
->lPos
<<16));
1445 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1446 infoPtr
->flags
&= ~TB_DRAG_MODE
;
1448 notify(infoPtr
, NM_RELEASEDCAPTURE
);
1449 TRACKBAR_ActivateToolTip(infoPtr
, FALSE
);
1450 TRACKBAR_InvalidateThumb(infoPtr
, infoPtr
->lPos
);
1452 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1453 KillTimer (infoPtr
->hwndSelf
, TB_REFRESH_TIMER
);
1454 infoPtr
->flags
&= ~TB_AUTO_PAGE
;
1455 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1457 notify(infoPtr
, NM_RELEASEDCAPTURE
);
1465 TRACKBAR_CaptureChanged (TRACKBAR_INFO
*infoPtr
)
1467 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1473 TRACKBAR_Paint (TRACKBAR_INFO
*infoPtr
, HDC hdc
)
1476 TRACKBAR_Refresh(infoPtr
, hdc
);
1479 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1480 TRACKBAR_Refresh (infoPtr
, hdc
);
1481 EndPaint (infoPtr
->hwndSelf
, &ps
);
1489 TRACKBAR_SetFocus (TRACKBAR_INFO
*infoPtr
, HWND hwndLoseFocus
)
1492 infoPtr
->bFocussed
= TRUE
;
1493 TRACKBAR_InvalidateAll(infoPtr
);
1500 TRACKBAR_Size (TRACKBAR_INFO
*infoPtr
, DWORD fwSizeType
, INT nWidth
, INT nHeight
)
1502 TRACKBAR_InitializeThumb (infoPtr
);
1503 TRACKBAR_AlignBuddies (infoPtr
);
1510 TRACKBAR_Timer (TRACKBAR_INFO
*infoPtr
, INT wTimerID
, TIMERPROC
*tmrpc
)
1512 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1514 if (GetCursorPos(&pt
))
1515 if (ScreenToClient(infoPtr
->hwndSelf
, &pt
))
1516 TRACKBAR_AutoPage(infoPtr
, pt
);
1523 TRACKBAR_MouseMove (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, INT x
, INT y
)
1525 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1526 INT clickPlace
= (dwStyle
& TBS_VERT
) ? y
: x
;
1527 LONG dragPos
, oldPos
= infoPtr
->lPos
;
1529 TRACE("(x=%d. y=%d)\n", x
, y
);
1531 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1535 TRACKBAR_AutoPage (infoPtr
, pt
);
1539 if (!(infoPtr
->flags
& TB_DRAG_MODE
)) return TRUE
;
1541 dragPos
= TRACKBAR_ConvertPlaceToPosition (infoPtr
, clickPlace
,
1542 dwStyle
& TBS_VERT
);
1543 if (dragPos
== oldPos
) return TRUE
;
1545 infoPtr
->lPos
= dragPos
;
1547 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1548 notify_with_scroll (infoPtr
, TB_THUMBTRACK
| (infoPtr
->lPos
<<16));
1551 TRACKBAR_InvalidateThumbMove(infoPtr
, oldPos
, dragPos
);
1552 UpdateWindow (infoPtr
->hwndSelf
);
1558 TRACKBAR_KeyDown (TRACKBAR_INFO
*infoPtr
, INT nVirtKey
, DWORD lKeyData
)
1560 DWORD style
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1561 BOOL downIsLeft
= style
& TBS_DOWNISLEFT
;
1562 BOOL vert
= style
& TBS_VERT
;
1563 LONG pos
= infoPtr
->lPos
;
1565 TRACE("%x\n", nVirtKey
);
1569 if (!vert
&& downIsLeft
) TRACKBAR_LineDown(infoPtr
);
1570 else TRACKBAR_LineUp(infoPtr
);
1573 if (vert
&& downIsLeft
) TRACKBAR_LineDown(infoPtr
);
1574 else TRACKBAR_LineUp(infoPtr
);
1577 if (!vert
&& downIsLeft
) TRACKBAR_LineUp(infoPtr
);
1578 else TRACKBAR_LineDown(infoPtr
);
1581 if (vert
&& downIsLeft
) TRACKBAR_LineUp(infoPtr
);
1582 else TRACKBAR_LineDown(infoPtr
);
1585 if (!vert
&& downIsLeft
) TRACKBAR_PageUp(infoPtr
);
1586 else TRACKBAR_PageDown(infoPtr
);
1589 if (!vert
&& downIsLeft
) TRACKBAR_PageDown(infoPtr
);
1590 else TRACKBAR_PageUp(infoPtr
);
1593 if (infoPtr
->lPos
== infoPtr
->lRangeMin
) return FALSE
;
1594 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1595 notify_with_scroll (infoPtr
, TB_TOP
);
1598 if (infoPtr
->lPos
== infoPtr
->lRangeMax
) return FALSE
;
1599 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1600 notify_with_scroll (infoPtr
, TB_BOTTOM
);
1604 if (pos
!= infoPtr
->lPos
) {
1605 infoPtr
->flags
|=TB_THUMBPOSCHANGED
;
1606 TRACKBAR_InvalidateThumbMove (infoPtr
, pos
, infoPtr
->lPos
);
1614 TRACKBAR_KeyUp (TRACKBAR_INFO
*infoPtr
, INT nVirtKey
, DWORD lKeyData
)
1625 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1631 static LRESULT WINAPI
1632 TRACKBAR_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1634 TRACKBAR_INFO
*infoPtr
= (TRACKBAR_INFO
*)GetWindowLongPtrW (hwnd
, 0);
1636 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
1638 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1639 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1644 return TRACKBAR_ClearSel (infoPtr
, (BOOL
)wParam
);
1647 return TRACKBAR_ClearTics (infoPtr
, (BOOL
)wParam
);
1650 return (LRESULT
)(wParam
? infoPtr
->hwndBuddyLA
: infoPtr
->hwndBuddyRB
);
1652 case TBM_GETCHANNELRECT
:
1653 return TRACKBAR_GetChannelRect (infoPtr
, (LPRECT
)lParam
);
1655 case TBM_GETLINESIZE
:
1656 return infoPtr
->lLineSize
;
1658 case TBM_GETNUMTICS
:
1659 return TRACKBAR_GetNumTics (infoPtr
);
1661 case TBM_GETPAGESIZE
:
1662 return infoPtr
->lPageSize
;
1665 return infoPtr
->lPos
;
1668 return (LRESULT
)infoPtr
->tics
;
1670 case TBM_GETRANGEMAX
:
1671 return infoPtr
->lRangeMax
;
1673 case TBM_GETRANGEMIN
:
1674 return infoPtr
->lRangeMin
;
1677 return infoPtr
->lSelMax
;
1679 case TBM_GETSELSTART
:
1680 return infoPtr
->lSelMin
;
1682 case TBM_GETTHUMBLENGTH
:
1683 return infoPtr
->uThumbLen
;
1685 case TBM_GETTHUMBRECT
:
1686 return CopyRect((LPRECT
)lParam
, &infoPtr
->rcThumb
);
1689 return TRACKBAR_GetTic (infoPtr
, (INT
)wParam
);
1692 return TRACKBAR_GetTicPos (infoPtr
, (INT
)wParam
);
1694 case TBM_GETTOOLTIPS
:
1695 return (LRESULT
)infoPtr
->hwndToolTip
;
1697 case TBM_GETUNICODEFORMAT
:
1698 return infoPtr
->bUnicode
;
1701 return (LRESULT
) TRACKBAR_SetBuddy(infoPtr
, (BOOL
)wParam
, (HWND
)lParam
);
1703 case TBM_SETLINESIZE
:
1704 return TRACKBAR_SetLineSize (infoPtr
, (LONG
)lParam
);
1706 case TBM_SETPAGESIZE
:
1707 return TRACKBAR_SetPageSize (infoPtr
, (LONG
)lParam
);
1710 return TRACKBAR_SetPos (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1713 return TRACKBAR_SetRange (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1715 case TBM_SETRANGEMAX
:
1716 return TRACKBAR_SetRangeMax (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1718 case TBM_SETRANGEMIN
:
1719 return TRACKBAR_SetRangeMin (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1722 return TRACKBAR_SetSel (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1725 return TRACKBAR_SetSelEnd (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1727 case TBM_SETSELSTART
:
1728 return TRACKBAR_SetSelStart (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1730 case TBM_SETTHUMBLENGTH
:
1731 return TRACKBAR_SetThumbLength (infoPtr
, (UINT
)wParam
);
1734 return TRACKBAR_SetTic (infoPtr
, (LONG
)lParam
);
1736 case TBM_SETTICFREQ
:
1737 return TRACKBAR_SetTicFreq (infoPtr
, (WORD
)wParam
);
1739 case TBM_SETTIPSIDE
:
1740 return TRACKBAR_SetTipSide (infoPtr
, (INT
)wParam
);
1742 case TBM_SETTOOLTIPS
:
1743 return TRACKBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
1745 case TBM_SETUNICODEFORMAT
:
1746 return TRACKBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1749 case WM_CAPTURECHANGED
:
1750 return TRACKBAR_CaptureChanged (infoPtr
);
1753 return TRACKBAR_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1756 return TRACKBAR_Destroy (infoPtr
);
1758 /* case WM_ENABLE: */
1764 return DLGC_WANTARROWS
;
1767 return TRACKBAR_KeyDown (infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
1770 return TRACKBAR_KeyUp (infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
1773 return TRACKBAR_KillFocus (infoPtr
, (HWND
)wParam
);
1775 case WM_LBUTTONDOWN
:
1776 return TRACKBAR_LButtonDown (infoPtr
, wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1779 return TRACKBAR_LButtonUp (infoPtr
, wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1782 return TRACKBAR_MouseMove (infoPtr
, wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1785 return TRACKBAR_Paint (infoPtr
, (HDC
)wParam
);
1788 return TRACKBAR_SetFocus (infoPtr
, (HWND
)wParam
);
1791 return TRACKBAR_Size (infoPtr
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1794 return TRACKBAR_Timer (infoPtr
, (INT
)wParam
, (TIMERPROC
*)lParam
);
1796 case WM_WININICHANGE
:
1797 return TRACKBAR_InitializeThumb (infoPtr
);
1800 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
1801 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
1802 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1807 void TRACKBAR_Register (void)
1811 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1812 wndClass
.style
= CS_GLOBALCLASS
;
1813 wndClass
.lpfnWndProc
= TRACKBAR_WindowProc
;
1814 wndClass
.cbClsExtra
= 0;
1815 wndClass
.cbWndExtra
= sizeof(TRACKBAR_INFO
*);
1816 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1817 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1818 wndClass
.lpszClassName
= TRACKBAR_CLASSW
;
1820 RegisterClassW (&wndClass
);
1824 void TRACKBAR_Unregister (void)
1826 UnregisterClassW (TRACKBAR_CLASSW
, NULL
);