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
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_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
)
566 int i
, ticFlags
= dwStyle
& 0x0f;
567 LOGPEN ticPen
= { PS_SOLID
, {1, 0}, GetSysColor (COLOR_3DDKSHADOW
) };
568 HPEN hOldPen
, hTicPen
;
570 /* create the pen to draw the tics with */
571 hTicPen
= CreatePenIndirect(&ticPen
);
572 hOldPen
= hTicPen
? SelectObject(hdc
, hTicPen
) : 0;
574 /* actually draw the tics */
575 for (i
=0; i
<infoPtr
->uNumTics
; i
++)
576 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->tics
[i
], ticFlags
);
578 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lRangeMin
, ticFlags
| TIC_EDGE
);
579 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lRangeMax
, ticFlags
| TIC_EDGE
);
581 if ((dwStyle
& TBS_ENABLESELRANGE
) && TRACKBAR_HasSelection(infoPtr
)) {
582 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lSelMin
,
583 ticFlags
| TIC_SELECTIONMARKMIN
);
584 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lSelMax
,
585 ticFlags
| TIC_SELECTIONMARKMAX
);
588 /* clean up the pen, if we created one */
590 SelectObject(hdc
, hOldPen
);
591 DeleteObject(hTicPen
);
596 TRACKBAR_DrawThumb(TRACKBAR_INFO
*infoPtr
, HDC hdc
, DWORD dwStyle
)
600 RECT thumb
= infoPtr
->rcThumb
;
607 fillClr
= infoPtr
->flags
& TB_DRAG_MODE
? COLOR_BTNHILIGHT
: COLOR_BTNFACE
;
608 oldbr
= SelectObject (hdc
, GetSysColorBrush(fillClr
));
609 SetPolyFillMode (hdc
, WINDING
);
611 if (dwStyle
& TBS_BOTH
)
613 points
[0].x
=thumb
.right
;
614 points
[0].y
=thumb
.top
;
615 points
[1].x
=thumb
.right
;
616 points
[1].y
=thumb
.bottom
;
617 points
[2].x
=thumb
.left
;
618 points
[2].y
=thumb
.bottom
;
619 points
[3].x
=thumb
.left
;
620 points
[3].y
=thumb
.top
;
621 points
[4].x
=points
[0].x
;
622 points
[4].y
=points
[0].y
;
628 if (dwStyle
& TBS_VERT
)
630 PointDepth
= (thumb
.bottom
- thumb
.top
) / 2;
631 if (dwStyle
& TBS_LEFT
)
633 points
[0].x
=thumb
.right
;
634 points
[0].y
=thumb
.top
;
635 points
[1].x
=thumb
.right
;
636 points
[1].y
=thumb
.bottom
;
637 points
[2].x
=thumb
.left
+ PointDepth
;
638 points
[2].y
=thumb
.bottom
;
639 points
[3].x
=thumb
.left
;
640 points
[3].y
=(thumb
.bottom
- thumb
.top
) / 2 + thumb
.top
+ 1;
641 points
[4].x
=thumb
.left
+ PointDepth
;
642 points
[4].y
=thumb
.top
;
643 points
[5].x
=points
[0].x
;
644 points
[5].y
=points
[0].y
;
649 points
[0].x
=thumb
.right
;
650 points
[0].y
=(thumb
.bottom
- thumb
.top
) / 2 + thumb
.top
+ 1;
651 points
[1].x
=thumb
.right
- PointDepth
;
652 points
[1].y
=thumb
.bottom
;
653 points
[2].x
=thumb
.left
;
654 points
[2].y
=thumb
.bottom
;
655 points
[3].x
=thumb
.left
;
656 points
[3].y
=thumb
.top
;
657 points
[4].x
=thumb
.right
- PointDepth
;
658 points
[4].y
=thumb
.top
;
659 points
[5].x
=points
[0].x
;
660 points
[5].y
=points
[0].y
;
665 PointDepth
= (thumb
.right
- thumb
.left
) / 2;
666 if (dwStyle
& TBS_TOP
)
668 points
[0].x
=(thumb
.right
- thumb
.left
) / 2 + thumb
.left
+ 1;
669 points
[0].y
=thumb
.top
;
670 points
[1].x
=thumb
.right
;
671 points
[1].y
=thumb
.top
+ PointDepth
;
672 points
[2].x
=thumb
.right
;
673 points
[2].y
=thumb
.bottom
;
674 points
[3].x
=thumb
.left
;
675 points
[3].y
=thumb
.bottom
;
676 points
[4].x
=thumb
.left
;
677 points
[4].y
=thumb
.top
+ PointDepth
;
678 points
[5].x
=points
[0].x
;
679 points
[5].y
=points
[0].y
;
684 points
[0].x
=thumb
.right
;
685 points
[0].y
=thumb
.top
;
686 points
[1].x
=thumb
.right
;
687 points
[1].y
=thumb
.bottom
- PointDepth
;
688 points
[2].x
=(thumb
.right
- thumb
.left
) / 2 + thumb
.left
+ 1;
689 points
[2].y
=thumb
.bottom
;
690 points
[3].x
=thumb
.left
;
691 points
[3].y
=thumb
.bottom
- PointDepth
;
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
;
701 /* Draw the thumb now */
702 Polygon (hdc
, points
, PointCount
);
703 oldpen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
704 Polyline(hdc
,points
, BlackUntil
);
705 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
706 Polyline(hdc
, &points
[BlackUntil
-1], PointCount
+1-BlackUntil
);
707 SelectObject(hdc
, oldpen
);
708 SelectObject(hdc
, oldbr
);
713 TRACKBAR_ActivateToolTip (TRACKBAR_INFO
*infoPtr
, BOOL fShow
)
717 if (!infoPtr
->hwndToolTip
) return;
719 ZeroMemory(&ti
, sizeof(ti
));
720 ti
.cbSize
= sizeof(ti
);
721 ti
.hwnd
= infoPtr
->hwndSelf
;
723 SendMessageW (infoPtr
->hwndToolTip
, TTM_TRACKACTIVATE
, fShow
, (LPARAM
)&ti
);
728 TRACKBAR_UpdateToolTip (TRACKBAR_INFO
*infoPtr
)
730 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
731 WCHAR buf
[80], fmt
[] = { '%', 'l', 'd', 0 };
737 if (!infoPtr
->hwndToolTip
) return;
739 ZeroMemory(&ti
, sizeof(ti
));
740 ti
.cbSize
= sizeof(ti
);
741 ti
.hwnd
= infoPtr
->hwndSelf
;
742 ti
.uFlags
= TTF_IDISHWND
| TTF_TRACK
| TTF_ABSOLUTE
;
744 wsprintfW (buf
, fmt
, infoPtr
->lPos
);
746 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
748 GetClientRect (infoPtr
->hwndSelf
, &rcClient
);
749 size
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETBUBBLESIZE
, 0, (LPARAM
)&ti
);
750 if (dwStyle
& TBS_VERT
) {
751 if (infoPtr
->fLocation
== TBTS_LEFT
)
752 pt
.x
= 0 - LOWORD(size
) - TOOLTIP_OFFSET
;
754 pt
.x
= rcClient
.right
+ TOOLTIP_OFFSET
;
755 pt
.y
= (infoPtr
->rcThumb
.top
+ infoPtr
->rcThumb
.bottom
- HIWORD(size
))/2;
757 if (infoPtr
->fLocation
== TBTS_TOP
)
758 pt
.y
= 0 - HIWORD(size
) - TOOLTIP_OFFSET
;
760 pt
.y
= rcClient
.bottom
+ TOOLTIP_OFFSET
;
761 pt
.x
= (infoPtr
->rcThumb
.left
+ infoPtr
->rcThumb
.right
- LOWORD(size
))/2;
763 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
765 SendMessageW (infoPtr
->hwndToolTip
, TTM_TRACKPOSITION
,
766 0, (LPARAM
)MAKELPARAM(pt
.x
, pt
.y
));
771 TRACKBAR_Refresh (TRACKBAR_INFO
*infoPtr
, HDC hdcDst
)
773 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
776 HBITMAP hOldBmp
= 0, hOffScreenBmp
= 0;
780 if (infoPtr
->flags
& TB_THUMBCHANGED
) {
781 TRACKBAR_UpdateThumb (infoPtr
);
782 if (infoPtr
->flags
& TB_THUMBSIZECHANGED
)
783 TRACKBAR_CalcChannel (infoPtr
);
785 if (infoPtr
->flags
& TB_SELECTIONCHANGED
)
786 TRACKBAR_CalcSelection (infoPtr
);
788 if (infoPtr
->flags
& TB_DRAG_MODE
)
789 TRACKBAR_UpdateToolTip (infoPtr
);
791 infoPtr
->flags
&= ~ (TB_THUMBCHANGED
| TB_SELECTIONCHANGED
);
793 GetClientRect (infoPtr
->hwndSelf
, &rcClient
);
795 /* try to render offscreen, if we fail, carrry onscreen */
796 hdc
= CreateCompatibleDC(hdcDst
);
798 hOffScreenBmp
= CreateCompatibleBitmap(hdcDst
, rcClient
.right
, rcClient
.bottom
);
800 hOldBmp
= SelectObject(hdc
, hOffScreenBmp
);
809 ZeroMemory(&nmcd
, sizeof(nmcd
));
810 nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
811 nmcd
.hdr
.idFrom
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_ID
);
812 nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
815 /* start the paint cycle */
817 gcdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_PREPAINT
);
818 if (gcdrf
& CDRF_SKIPDEFAULT
) goto cleanup
;
820 /* Erase backbround */
821 if (gcdrf
== CDRF_DODEFAULT
||
822 notify_customdraw(infoPtr
, &nmcd
, CDDS_PREERASE
) != CDRF_SKIPDEFAULT
) {
823 FillRect (hdc
, &rcClient
, GetSysColorBrush(COLOR_BTNFACE
));
824 if (gcdrf
!= CDRF_DODEFAULT
)
825 notify_customdraw(infoPtr
, &nmcd
, CDDS_POSTERASE
);
829 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
830 nmcd
.dwItemSpec
= TBCD_CHANNEL
;
831 nmcd
.uItemState
= CDIS_DEFAULT
;
832 nmcd
.rc
= infoPtr
->rcChannel
;
833 icdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPREPAINT
);
834 } else icdrf
= CDRF_DODEFAULT
;
835 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
836 TRACKBAR_DrawChannel (infoPtr
, hdc
, dwStyle
);
837 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
838 notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPOSTPAINT
);
843 if (!(dwStyle
& TBS_NOTICKS
)) {
844 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
845 nmcd
.dwItemSpec
= TBCD_TICS
;
846 nmcd
.uItemState
= CDIS_DEFAULT
;
848 icdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPREPAINT
);
849 } else icdrf
= CDRF_DODEFAULT
;
850 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
851 TRACKBAR_DrawTics (infoPtr
, hdc
, dwStyle
);
852 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
853 notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPOSTPAINT
);
858 if (!(dwStyle
& TBS_NOTHUMB
)) {
859 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
860 nmcd
.dwItemSpec
= TBCD_THUMB
;
861 nmcd
.uItemState
= infoPtr
->flags
& TB_DRAG_MODE
? CDIS_HOT
: CDIS_DEFAULT
;
862 nmcd
.rc
= infoPtr
->rcThumb
;
863 icdrf
= notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPREPAINT
);
864 } else icdrf
= CDRF_DODEFAULT
;
865 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
866 TRACKBAR_DrawThumb(infoPtr
, hdc
, dwStyle
);
867 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
868 notify_customdraw(infoPtr
, &nmcd
, CDDS_ITEMPOSTPAINT
);
872 /* draw focus rectangle */
873 if (infoPtr
->bFocussed
) {
874 DrawFocusRect(hdc
, &rcClient
);
877 /* finish up the painting */
878 if (gcdrf
& CDRF_NOTIFYPOSTPAINT
)
879 notify_customdraw(infoPtr
, &nmcd
, CDDS_POSTPAINT
);
882 /* cleanup, if we rendered offscreen */
884 BitBlt(hdcDst
, 0, 0, rcClient
.right
, rcClient
.bottom
, hdc
, 0, 0, SRCCOPY
);
885 SelectObject(hdc
, hOldBmp
);
886 DeleteObject(hOffScreenBmp
);
893 TRACKBAR_AlignBuddies (TRACKBAR_INFO
*infoPtr
)
895 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
896 HWND hwndParent
= GetParent (infoPtr
->hwndSelf
);
897 RECT rcSelf
, rcBuddy
;
900 GetWindowRect (infoPtr
->hwndSelf
, &rcSelf
);
901 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcSelf
, 2);
903 /* align buddy left or above */
904 if (infoPtr
->hwndBuddyLA
) {
905 GetWindowRect (infoPtr
->hwndBuddyLA
, &rcBuddy
);
906 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcBuddy
, 2);
908 if (dwStyle
& TBS_VERT
) {
909 x
= (infoPtr
->rcChannel
.right
+ infoPtr
->rcChannel
.left
) / 2 -
910 (rcBuddy
.right
- rcBuddy
.left
) / 2 + rcSelf
.left
;
911 y
= rcSelf
.top
- (rcBuddy
.bottom
- rcBuddy
.top
);
914 x
= rcSelf
.left
- (rcBuddy
.right
- rcBuddy
.left
);
915 y
= (infoPtr
->rcChannel
.bottom
+ infoPtr
->rcChannel
.top
) / 2 -
916 (rcBuddy
.bottom
- rcBuddy
.top
) / 2 + rcSelf
.top
;
919 SetWindowPos (infoPtr
->hwndBuddyLA
, 0, x
, y
, 0, 0,
920 SWP_NOZORDER
| SWP_NOSIZE
);
924 /* align buddy right or below */
925 if (infoPtr
->hwndBuddyRB
) {
926 GetWindowRect (infoPtr
->hwndBuddyRB
, &rcBuddy
);
927 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcBuddy
, 2);
929 if (dwStyle
& TBS_VERT
) {
930 x
= (infoPtr
->rcChannel
.right
+ infoPtr
->rcChannel
.left
) / 2 -
931 (rcBuddy
.right
- rcBuddy
.left
) / 2 + rcSelf
.left
;
936 y
= (infoPtr
->rcChannel
.bottom
+ infoPtr
->rcChannel
.top
) / 2 -
937 (rcBuddy
.bottom
- rcBuddy
.top
) / 2 + rcSelf
.top
;
939 SetWindowPos (infoPtr
->hwndBuddyRB
, 0, x
, y
, 0, 0,
940 SWP_NOZORDER
| SWP_NOSIZE
);
946 TRACKBAR_ClearSel (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
)
948 infoPtr
->lSelMin
= 0;
949 infoPtr
->lSelMax
= 0;
950 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
952 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
959 TRACKBAR_ClearTics (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
)
962 Free (infoPtr
->tics
);
963 infoPtr
->tics
= NULL
;
964 infoPtr
->uNumTics
= 0;
967 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
973 static LRESULT
inline
974 TRACKBAR_GetChannelRect (TRACKBAR_INFO
*infoPtr
, LPRECT lprc
)
976 if (lprc
== NULL
) return 0;
978 lprc
->left
= infoPtr
->rcChannel
.left
;
979 lprc
->right
= infoPtr
->rcChannel
.right
;
980 lprc
->bottom
= infoPtr
->rcChannel
.bottom
;
981 lprc
->top
= infoPtr
->rcChannel
.top
;
988 TRACKBAR_GetNumTics (TRACKBAR_INFO
*infoPtr
)
990 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_NOTICKS
)
993 return infoPtr
->uNumTics
+ 2;
997 static int comp_tics(const void *ap
, const void *bp
)
999 DWORD a
= *((DWORD
*)ap
);
1000 DWORD b
= *((DWORD
*)bp
);
1002 TRACE("(a=%ld, b=%ld)\n", a
, b
);
1003 if (a
< b
) return -1;
1004 if (a
> b
) return 1;
1010 TRACKBAR_GetTic (TRACKBAR_INFO
*infoPtr
, INT iTic
)
1012 if ((iTic
< 0) || (iTic
>= infoPtr
->uNumTics
) || !infoPtr
->tics
)
1015 qsort(infoPtr
->tics
, infoPtr
->uNumTics
, sizeof(DWORD
), comp_tics
);
1016 return infoPtr
->tics
[iTic
];
1021 TRACKBAR_GetTicPos (TRACKBAR_INFO
*infoPtr
, INT iTic
)
1023 LONG range
, width
, pos
, tic
;
1026 if ((iTic
< 0) || (iTic
>= infoPtr
->uNumTics
) || !infoPtr
->tics
)
1029 tic
= TRACKBAR_GetTic (infoPtr
, iTic
);
1030 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
1031 if (range
<= 0) range
= 1;
1032 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
1033 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- offsetthumb
*2;
1034 pos
= infoPtr
->rcChannel
.left
+ offsetthumb
+ (width
* tic
) / range
;
1041 TRACKBAR_SetBuddy (TRACKBAR_INFO
*infoPtr
, BOOL fLocation
, HWND hwndBuddy
)
1046 /* buddy is left or above */
1047 hwndTemp
= infoPtr
->hwndBuddyLA
;
1048 infoPtr
->hwndBuddyLA
= hwndBuddy
;
1051 /* buddy is right or below */
1052 hwndTemp
= infoPtr
->hwndBuddyRB
;
1053 infoPtr
->hwndBuddyRB
= hwndBuddy
;
1056 TRACKBAR_AlignBuddies (infoPtr
);
1063 TRACKBAR_SetLineSize (TRACKBAR_INFO
*infoPtr
, LONG lLineSize
)
1065 LONG lTemp
= infoPtr
->lLineSize
;
1067 infoPtr
->lLineSize
= lLineSize
;
1074 TRACKBAR_SetPageSize (TRACKBAR_INFO
*infoPtr
, LONG lPageSize
)
1076 LONG lTemp
= infoPtr
->lPageSize
;
1078 infoPtr
->lPageSize
= lPageSize
;
1084 static LRESULT
inline
1085 TRACKBAR_SetPos (TRACKBAR_INFO
*infoPtr
, BOOL fPosition
, LONG lPosition
)
1087 LONG oldPos
= infoPtr
->lPos
;
1088 infoPtr
->lPos
= lPosition
;
1090 if (infoPtr
->lPos
< infoPtr
->lRangeMin
)
1091 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1093 if (infoPtr
->lPos
> infoPtr
->lRangeMax
)
1094 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1095 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1097 if (fPosition
) TRACKBAR_InvalidateThumbMove(infoPtr
, oldPos
, lPosition
);
1103 static LRESULT
inline
1104 TRACKBAR_SetRange (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lRange
)
1106 infoPtr
->lRangeMin
= (SHORT
)LOWORD(lRange
);
1107 infoPtr
->lRangeMax
= (SHORT
)HIWORD(lRange
);
1109 if (infoPtr
->lPos
< infoPtr
->lRangeMin
) {
1110 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1111 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1114 if (infoPtr
->lPos
> infoPtr
->lRangeMax
) {
1115 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1116 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1119 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1120 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1122 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1128 static LRESULT
inline
1129 TRACKBAR_SetRangeMax (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lMax
)
1131 infoPtr
->lRangeMax
= lMax
;
1132 if (infoPtr
->lPos
> infoPtr
->lRangeMax
) {
1133 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1134 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1137 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1138 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1140 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1146 static LRESULT
inline
1147 TRACKBAR_SetRangeMin (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lMin
)
1149 infoPtr
->lRangeMin
= lMin
;
1150 if (infoPtr
->lPos
< infoPtr
->lRangeMin
) {
1151 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1152 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1155 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1156 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1158 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1164 static LRESULT
inline
1165 TRACKBAR_SetSel (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lSel
)
1167 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1170 infoPtr
->lSelMin
= (SHORT
)LOWORD(lSel
);
1171 infoPtr
->lSelMax
= (SHORT
)HIWORD(lSel
);
1172 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
1174 if (infoPtr
->lSelMin
< infoPtr
->lRangeMin
)
1175 infoPtr
->lSelMin
= infoPtr
->lRangeMin
;
1176 if (infoPtr
->lSelMax
> infoPtr
->lRangeMax
)
1177 infoPtr
->lSelMax
= infoPtr
->lRangeMax
;
1179 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1185 static LRESULT
inline
1186 TRACKBAR_SetSelEnd (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lEnd
)
1188 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1191 infoPtr
->lSelMax
= lEnd
;
1192 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
1194 if (infoPtr
->lSelMax
> infoPtr
->lRangeMax
)
1195 infoPtr
->lSelMax
= infoPtr
->lRangeMax
;
1197 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1203 static LRESULT
inline
1204 TRACKBAR_SetSelStart (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lStart
)
1206 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1209 infoPtr
->lSelMin
= lStart
;
1210 infoPtr
->flags
|=TB_SELECTIONCHANGED
;
1212 if (infoPtr
->lSelMin
< infoPtr
->lRangeMin
)
1213 infoPtr
->lSelMin
= infoPtr
->lRangeMin
;
1215 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1221 static LRESULT
inline
1222 TRACKBAR_SetThumbLength (TRACKBAR_INFO
*infoPtr
, UINT iLength
)
1224 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_FIXEDLENGTH
) {
1225 infoPtr
->uThumbLen
= iLength
;
1226 infoPtr
->flags
|= TB_THUMBSIZECHANGED
;
1227 InvalidateRect (infoPtr
->hwndSelf
, &infoPtr
->rcThumb
, FALSE
);
1234 static LRESULT
inline
1235 TRACKBAR_SetTic (TRACKBAR_INFO
*infoPtr
, LONG lPos
)
1237 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_AUTOTICKS
)
1240 if ((lPos
< infoPtr
->lRangeMin
) || (lPos
> infoPtr
->lRangeMax
))
1243 TRACE("lPos=%ld\n", lPos
);
1245 infoPtr
->uNumTics
++;
1246 infoPtr
->tics
=ReAlloc( infoPtr
->tics
,
1247 (infoPtr
->uNumTics
)*sizeof (DWORD
));
1248 if (!infoPtr
->tics
) {
1249 infoPtr
->uNumTics
= 0;
1250 notify(infoPtr
, NM_OUTOFMEMORY
);
1253 infoPtr
->tics
[infoPtr
->uNumTics
-1] = lPos
;
1255 TRACKBAR_InvalidateAll(infoPtr
);
1261 static LRESULT
inline
1262 TRACKBAR_SetTicFreq (TRACKBAR_INFO
*infoPtr
, WORD wFreq
)
1264 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_AUTOTICKS
) {
1265 infoPtr
->uTicFreq
= wFreq
;
1266 TRACKBAR_RecalculateTics (infoPtr
);
1267 TRACKBAR_InvalidateAll(infoPtr
);
1275 TRACKBAR_SetTipSide (TRACKBAR_INFO
*infoPtr
, INT fLocation
)
1277 INT fTemp
= infoPtr
->fLocation
;
1279 infoPtr
->fLocation
= fLocation
;
1285 static LRESULT
inline
1286 TRACKBAR_SetToolTips (TRACKBAR_INFO
*infoPtr
, HWND hwndTT
)
1288 infoPtr
->hwndToolTip
= hwndTT
;
1295 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO
*infoPtr
, BOOL fUnicode
)
1297 BOOL bTemp
= infoPtr
->bUnicode
;
1299 infoPtr
->bUnicode
= fUnicode
;
1306 TRACKBAR_InitializeThumb (TRACKBAR_INFO
*infoPtr
)
1308 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1310 int clientWidth
, clientMetric
;
1312 /* initial thumb length */
1313 clientMetric
= (dwStyle
& TBS_ENABLESELRANGE
) ? 23 : 21;
1314 GetClientRect(infoPtr
->hwndSelf
,&rect
);
1315 if (dwStyle
& TBS_VERT
) {
1316 clientWidth
= rect
.right
- rect
.left
;
1318 clientWidth
= rect
.bottom
- rect
.top
;
1320 if (clientWidth
>= clientMetric
)
1321 infoPtr
->uThumbLen
= clientMetric
;
1323 infoPtr
->uThumbLen
= clientWidth
> 9 ? clientWidth
- 6 : 4;
1325 TRACKBAR_CalcChannel (infoPtr
);
1326 TRACKBAR_UpdateThumb (infoPtr
);
1327 infoPtr
->flags
&= ~TB_SELECTIONCHANGED
;
1334 TRACKBAR_Create (HWND hwnd
, LPCREATESTRUCTW lpcs
)
1336 TRACKBAR_INFO
*infoPtr
;
1337 DWORD oldStyle
, newStyle
;
1339 infoPtr
= (TRACKBAR_INFO
*)Alloc (sizeof(TRACKBAR_INFO
));
1340 if (!infoPtr
) return -1;
1341 SetWindowLongW (hwnd
, 0, (DWORD
)infoPtr
);
1343 /* set default values */
1344 infoPtr
->hwndSelf
= hwnd
;
1345 infoPtr
->lRangeMin
= 0;
1346 infoPtr
->lRangeMax
= 100;
1347 infoPtr
->lLineSize
= 1;
1348 infoPtr
->lPageSize
= 20;
1349 infoPtr
->lSelMin
= 0;
1350 infoPtr
->lSelMax
= 0;
1352 infoPtr
->fLocation
= -1;
1353 infoPtr
->uNumTics
= 0; /* start and end tic are not included in count*/
1354 infoPtr
->uTicFreq
= 1;
1355 infoPtr
->tics
= NULL
;
1356 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1358 TRACKBAR_InitializeThumb (infoPtr
);
1360 oldStyle
= newStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1361 if (oldStyle
& TBS_VERT
) {
1362 if (! (oldStyle
& (TBS_LEFT
| TBS_RIGHT
| TBS_BOTH
)) )
1363 newStyle
|= TBS_RIGHT
;
1365 if (! (oldStyle
& (TBS_TOP
| TBS_BOTTOM
| TBS_BOTH
)) )
1366 newStyle
|= TBS_BOTTOM
;
1368 if (newStyle
!= oldStyle
)
1369 SetWindowLongW (hwnd
, GWL_STYLE
, newStyle
);
1371 /* Create tooltip control */
1372 if (newStyle
& TBS_TOOLTIPS
) {
1374 infoPtr
->hwndToolTip
=
1375 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, 0,
1376 CW_USEDEFAULT
, CW_USEDEFAULT
,
1377 CW_USEDEFAULT
, CW_USEDEFAULT
,
1380 if (infoPtr
->hwndToolTip
) {
1382 ZeroMemory (&ti
, sizeof(ti
));
1383 ti
.cbSize
= sizeof(ti
);
1384 ti
.uFlags
= TTF_IDISHWND
| TTF_TRACK
| TTF_ABSOLUTE
;
1387 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&ti
);
1396 TRACKBAR_Destroy (TRACKBAR_INFO
*infoPtr
)
1398 /* delete tooltip control */
1399 if (infoPtr
->hwndToolTip
)
1400 DestroyWindow (infoPtr
->hwndToolTip
);
1403 SetWindowLongW (infoPtr
->hwndSelf
, 0, 0);
1409 TRACKBAR_KillFocus (TRACKBAR_INFO
*infoPtr
, HWND hwndGetFocus
)
1412 infoPtr
->bFocussed
= FALSE
;
1413 TRACKBAR_InvalidateAll(infoPtr
);
1419 TRACKBAR_LButtonDown (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, POINTS pts
)
1421 POINT clickPoint
= { pts
.x
, pts
.y
};
1423 SetFocus(infoPtr
->hwndSelf
);
1425 if (PtInRect(&infoPtr
->rcThumb
, clickPoint
)) {
1426 infoPtr
->flags
|= TB_DRAG_MODE
;
1427 SetCapture (infoPtr
->hwndSelf
);
1428 TRACKBAR_UpdateToolTip (infoPtr
);
1429 TRACKBAR_ActivateToolTip (infoPtr
, TRUE
);
1430 TRACKBAR_InvalidateThumb(infoPtr
, infoPtr
->lPos
);
1432 LONG dir
= TRACKBAR_GetAutoPageDirection(infoPtr
, clickPoint
);
1433 if (dir
== 0) return 0;
1434 infoPtr
->flags
|= (dir
< 0) ? TB_AUTO_PAGE_LEFT
: TB_AUTO_PAGE_RIGHT
;
1435 TRACKBAR_AutoPage (infoPtr
, clickPoint
);
1436 SetCapture (infoPtr
->hwndSelf
);
1437 SetTimer(infoPtr
->hwndSelf
, TB_REFRESH_TIMER
, TB_REFRESH_DELAY
, 0);
1445 TRACKBAR_LButtonUp (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, POINTS pts
)
1447 if (infoPtr
->flags
& TB_DRAG_MODE
) {
1448 notify_with_scroll (infoPtr
, TB_THUMBPOSITION
| (infoPtr
->lPos
<<16));
1449 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1450 infoPtr
->flags
&= ~TB_DRAG_MODE
;
1452 notify(infoPtr
, NM_RELEASEDCAPTURE
);
1453 TRACKBAR_ActivateToolTip(infoPtr
, FALSE
);
1454 TRACKBAR_InvalidateThumb(infoPtr
, infoPtr
->lPos
);
1456 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1457 KillTimer (infoPtr
->hwndSelf
, TB_REFRESH_TIMER
);
1458 infoPtr
->flags
&= ~TB_AUTO_PAGE
;
1459 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1461 notify(infoPtr
, NM_RELEASEDCAPTURE
);
1469 TRACKBAR_CaptureChanged (TRACKBAR_INFO
*infoPtr
)
1471 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1477 TRACKBAR_Paint (TRACKBAR_INFO
*infoPtr
, HDC hdc
)
1480 TRACKBAR_Refresh(infoPtr
, hdc
);
1483 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1484 TRACKBAR_Refresh (infoPtr
, hdc
);
1485 EndPaint (infoPtr
->hwndSelf
, &ps
);
1493 TRACKBAR_SetFocus (TRACKBAR_INFO
*infoPtr
, HWND hwndLoseFocus
)
1496 infoPtr
->bFocussed
= TRUE
;
1497 TRACKBAR_InvalidateAll(infoPtr
);
1504 TRACKBAR_Size (TRACKBAR_INFO
*infoPtr
, DWORD fwSizeType
, INT nWidth
, INT nHeight
)
1506 TRACKBAR_InitializeThumb (infoPtr
);
1507 TRACKBAR_AlignBuddies (infoPtr
);
1514 TRACKBAR_Timer (TRACKBAR_INFO
*infoPtr
, INT wTimerID
, TIMERPROC
*tmrpc
)
1516 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1518 if (GetCursorPos(&pt
))
1519 if (ScreenToClient(infoPtr
->hwndSelf
, &pt
))
1520 TRACKBAR_AutoPage(infoPtr
, pt
);
1527 TRACKBAR_MouseMove (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, POINTS pts
)
1529 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1530 INT clickPlace
= (dwStyle
& TBS_VERT
) ? pts
.y
: pts
.x
;
1531 LONG dragPos
, oldPos
= infoPtr
->lPos
;
1533 TRACE("(x=%d. y=%d)\n", pts
.x
, pts
.y
);
1535 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1537 POINTSTOPOINT(pt
, pts
);
1538 TRACKBAR_AutoPage (infoPtr
, pt
);
1542 if (!(infoPtr
->flags
& TB_DRAG_MODE
)) return TRUE
;
1544 dragPos
= TRACKBAR_ConvertPlaceToPosition (infoPtr
, clickPlace
,
1545 dwStyle
& TBS_VERT
);
1546 if (dragPos
== oldPos
) return TRUE
;
1548 infoPtr
->lPos
= dragPos
;
1550 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1551 notify_with_scroll (infoPtr
, TB_THUMBTRACK
| (infoPtr
->lPos
<<16));
1554 TRACKBAR_InvalidateThumbMove(infoPtr
, oldPos
, dragPos
);
1555 UpdateWindow (infoPtr
->hwndSelf
);
1561 TRACKBAR_KeyDown (TRACKBAR_INFO
*infoPtr
, INT nVirtKey
, DWORD lKeyData
)
1563 DWORD style
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1564 BOOL downIsLeft
= style
& TBS_DOWNISLEFT
;
1565 BOOL vert
= style
& TBS_VERT
;
1566 LONG pos
= infoPtr
->lPos
;
1568 TRACE("%x\n", nVirtKey
);
1572 if (!vert
&& downIsLeft
) TRACKBAR_LineDown(infoPtr
);
1573 else TRACKBAR_LineUp(infoPtr
);
1576 if (vert
&& downIsLeft
) TRACKBAR_LineDown(infoPtr
);
1577 else TRACKBAR_LineUp(infoPtr
);
1580 if (!vert
&& downIsLeft
) TRACKBAR_LineUp(infoPtr
);
1581 else TRACKBAR_LineDown(infoPtr
);
1584 if (vert
&& downIsLeft
) TRACKBAR_LineUp(infoPtr
);
1585 else TRACKBAR_LineDown(infoPtr
);
1588 if (!vert
&& downIsLeft
) TRACKBAR_PageUp(infoPtr
);
1589 else TRACKBAR_PageDown(infoPtr
);
1592 if (!vert
&& downIsLeft
) TRACKBAR_PageDown(infoPtr
);
1593 else TRACKBAR_PageUp(infoPtr
);
1596 if (infoPtr
->lPos
== infoPtr
->lRangeMin
) return FALSE
;
1597 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1598 notify_with_scroll (infoPtr
, TB_TOP
);
1601 if (infoPtr
->lPos
== infoPtr
->lRangeMax
) return FALSE
;
1602 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1603 notify_with_scroll (infoPtr
, TB_BOTTOM
);
1607 if (pos
!= infoPtr
->lPos
) {
1608 infoPtr
->flags
|=TB_THUMBPOSCHANGED
;
1609 TRACKBAR_InvalidateThumbMove (infoPtr
, pos
, infoPtr
->lPos
);
1617 TRACKBAR_KeyUp (TRACKBAR_INFO
*infoPtr
, INT nVirtKey
, DWORD lKeyData
)
1628 notify_with_scroll (infoPtr
, TB_ENDTRACK
);
1634 static LRESULT WINAPI
1635 TRACKBAR_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1637 TRACKBAR_INFO
*infoPtr
= (TRACKBAR_INFO
*)GetWindowLongW (hwnd
, 0);
1639 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
1641 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1642 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1647 return TRACKBAR_ClearSel (infoPtr
, (BOOL
)wParam
);
1650 return TRACKBAR_ClearTics (infoPtr
, (BOOL
)wParam
);
1653 return (LRESULT
)(wParam
? infoPtr
->hwndBuddyLA
: infoPtr
->hwndBuddyRB
);
1655 case TBM_GETCHANNELRECT
:
1656 return TRACKBAR_GetChannelRect (infoPtr
, (LPRECT
)lParam
);
1658 case TBM_GETLINESIZE
:
1659 return infoPtr
->lLineSize
;
1661 case TBM_GETNUMTICS
:
1662 return TRACKBAR_GetNumTics (infoPtr
);
1664 case TBM_GETPAGESIZE
:
1665 return infoPtr
->lPageSize
;
1668 return infoPtr
->lPos
;
1671 return (LRESULT
)infoPtr
->tics
;
1673 case TBM_GETRANGEMAX
:
1674 return infoPtr
->lRangeMax
;
1676 case TBM_GETRANGEMIN
:
1677 return infoPtr
->lRangeMin
;
1680 return infoPtr
->lSelMax
;
1682 case TBM_GETSELSTART
:
1683 return infoPtr
->lSelMin
;
1685 case TBM_GETTHUMBLENGTH
:
1686 return infoPtr
->uThumbLen
;
1688 case TBM_GETTHUMBRECT
:
1689 return CopyRect((LPRECT
)lParam
, &infoPtr
->rcThumb
);
1692 return TRACKBAR_GetTic (infoPtr
, (INT
)wParam
);
1695 return TRACKBAR_GetTicPos (infoPtr
, (INT
)wParam
);
1697 case TBM_GETTOOLTIPS
:
1698 return (LRESULT
)infoPtr
->hwndToolTip
;
1700 case TBM_GETUNICODEFORMAT
:
1701 return infoPtr
->bUnicode
;
1704 return (LRESULT
) TRACKBAR_SetBuddy(infoPtr
, (BOOL
)wParam
, (HWND
)lParam
);
1706 case TBM_SETLINESIZE
:
1707 return TRACKBAR_SetLineSize (infoPtr
, (LONG
)lParam
);
1709 case TBM_SETPAGESIZE
:
1710 return TRACKBAR_SetPageSize (infoPtr
, (LONG
)lParam
);
1713 return TRACKBAR_SetPos (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1716 return TRACKBAR_SetRange (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1718 case TBM_SETRANGEMAX
:
1719 return TRACKBAR_SetRangeMax (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1721 case TBM_SETRANGEMIN
:
1722 return TRACKBAR_SetRangeMin (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1725 return TRACKBAR_SetSel (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1728 return TRACKBAR_SetSelEnd (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1730 case TBM_SETSELSTART
:
1731 return TRACKBAR_SetSelStart (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1733 case TBM_SETTHUMBLENGTH
:
1734 return TRACKBAR_SetThumbLength (infoPtr
, (UINT
)wParam
);
1737 return TRACKBAR_SetTic (infoPtr
, (LONG
)lParam
);
1739 case TBM_SETTICFREQ
:
1740 return TRACKBAR_SetTicFreq (infoPtr
, (WORD
)wParam
);
1742 case TBM_SETTIPSIDE
:
1743 return TRACKBAR_SetTipSide (infoPtr
, (INT
)wParam
);
1745 case TBM_SETTOOLTIPS
:
1746 return TRACKBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
1748 case TBM_SETUNICODEFORMAT
:
1749 return TRACKBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1752 case WM_CAPTURECHANGED
:
1753 return TRACKBAR_CaptureChanged (infoPtr
);
1756 return TRACKBAR_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1759 return TRACKBAR_Destroy (infoPtr
);
1761 /* case WM_ENABLE: */
1767 return DLGC_WANTARROWS
;
1770 return TRACKBAR_KeyDown (infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
1773 return TRACKBAR_KeyUp (infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
1776 return TRACKBAR_KillFocus (infoPtr
, (HWND
)wParam
);
1778 case WM_LBUTTONDOWN
:
1779 return TRACKBAR_LButtonDown (infoPtr
, wParam
, MAKEPOINTS(lParam
));
1782 return TRACKBAR_LButtonUp (infoPtr
, wParam
, MAKEPOINTS(lParam
));
1785 return TRACKBAR_MouseMove (infoPtr
, wParam
, MAKEPOINTS(lParam
));
1788 return TRACKBAR_Paint (infoPtr
, (HDC
)wParam
);
1791 return TRACKBAR_SetFocus (infoPtr
, (HWND
)wParam
);
1794 return TRACKBAR_Size (infoPtr
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1797 return TRACKBAR_Timer (infoPtr
, (INT
)wParam
, (TIMERPROC
*)lParam
);
1799 case WM_WININICHANGE
:
1800 return TRACKBAR_InitializeThumb (infoPtr
);
1803 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
1804 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
1805 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1811 void TRACKBAR_Register (void)
1815 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1816 wndClass
.style
= CS_GLOBALCLASS
;
1817 wndClass
.lpfnWndProc
= (WNDPROC
)TRACKBAR_WindowProc
;
1818 wndClass
.cbClsExtra
= 0;
1819 wndClass
.cbWndExtra
= sizeof(TRACKBAR_INFO
*);
1820 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1821 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
1822 wndClass
.lpszClassName
= TRACKBAR_CLASSW
;
1824 RegisterClassW (&wndClass
);
1828 void TRACKBAR_Unregister (void)
1830 UnregisterClassW (TRACKBAR_CLASSW
, NULL
);