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)
100 static BOOL
TRACKBAR_SendNotify (TRACKBAR_INFO
*infoPtr
, UINT code
);
103 notify_customdraw(NMCUSTOMDRAW
*pnmcd
, int stage
)
105 pnmcd
->dwDrawStage
= stage
;
106 return SendMessageW (GetParent(pnmcd
->hdr
.hwndFrom
), WM_NOTIFY
,
107 pnmcd
->hdr
.idFrom
, (LPARAM
)pnmcd
);
110 static void TRACKBAR_RecalculateTics (TRACKBAR_INFO
*infoPtr
)
114 if (infoPtr
->uTicFreq
&& infoPtr
->lRangeMax
>= infoPtr
->lRangeMin
)
115 nrTics
=(infoPtr
->lRangeMax
- infoPtr
->lRangeMin
)/infoPtr
->uTicFreq
;
118 COMCTL32_Free (infoPtr
->tics
);
119 infoPtr
->tics
= NULL
;
120 infoPtr
->uNumTics
= 0;
124 if (nrTics
!= infoPtr
->uNumTics
) {
125 infoPtr
->tics
=COMCTL32_ReAlloc (infoPtr
->tics
,
126 (nrTics
+1)*sizeof (DWORD
));
127 if (!infoPtr
->tics
) {
128 infoPtr
->uNumTics
= 0;
129 TRACKBAR_SendNotify(infoPtr
, NM_OUTOFMEMORY
);
132 infoPtr
->uNumTics
= nrTics
;
135 tic
= infoPtr
->lRangeMin
+ infoPtr
->uTicFreq
;
136 for (i
= 0; i
< nrTics
; i
++, tic
+= infoPtr
->uTicFreq
)
137 infoPtr
->tics
[i
] = tic
;
140 /* converts from physical (mouse) position to logical position
141 (in range of trackbar) */
144 TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO
*infoPtr
, int place
,
147 double range
, width
, pos
, offsetthumb
;
149 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
151 offsetthumb
= (infoPtr
->rcThumb
.bottom
- infoPtr
->rcThumb
.top
)/2;
152 width
= infoPtr
->rcChannel
.bottom
- infoPtr
->rcChannel
.top
- (offsetthumb
* 2) - 1;
153 pos
= (range
*(place
- infoPtr
->rcChannel
.top
- offsetthumb
)) / width
;
155 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
156 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- (offsetthumb
* 2) - 1;
157 pos
= (range
*(place
- infoPtr
->rcChannel
.left
- offsetthumb
)) / width
;
159 pos
+= infoPtr
->lRangeMin
;
160 if (pos
> infoPtr
->lRangeMax
)
161 pos
= infoPtr
->lRangeMax
;
162 else if (pos
< infoPtr
->lRangeMin
)
163 pos
= infoPtr
->lRangeMin
;
165 TRACE("%.2f\n", pos
);
166 return (LONG
)(pos
+ 0.5);
170 /* return: 0> prev, 0 none, >0 next */
172 TRACKBAR_GetAutoPageDirection (TRACKBAR_INFO
*infoPtr
, POINT clickPoint
)
174 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
177 if (dwStyle
& TBS_VERT
) {
178 pageRect
.top
= infoPtr
->rcChannel
.top
;
179 pageRect
.bottom
= infoPtr
->rcChannel
.bottom
;
180 pageRect
.left
= infoPtr
->rcThumb
.left
;
181 pageRect
.right
= infoPtr
->rcThumb
.right
;
183 pageRect
.top
= infoPtr
->rcThumb
.top
;
184 pageRect
.bottom
= infoPtr
->rcThumb
.bottom
;
185 pageRect
.left
= infoPtr
->rcChannel
.left
;
186 pageRect
.right
= infoPtr
->rcChannel
.right
;
190 if (PtInRect(&pageRect
, clickPoint
))
192 int clickPlace
= (dwStyle
& TBS_VERT
) ? clickPoint
.y
: clickPoint
.x
;
194 LONG clickPos
= TRACKBAR_ConvertPlaceToPosition(infoPtr
, clickPlace
,
196 return clickPos
- infoPtr
->lPos
;
203 TRACKBAR_PageUp (TRACKBAR_INFO
*infoPtr
)
205 if (infoPtr
->lPos
== infoPtr
->lRangeMax
) return;
207 infoPtr
->lPos
+= infoPtr
->lPageSize
;
208 if (infoPtr
->lPos
> infoPtr
->lRangeMax
)
209 infoPtr
->lPos
= infoPtr
->lRangeMax
;
210 TRACKBAR_SendNotify (infoPtr
, TB_PAGEUP
);
215 TRACKBAR_PageDown (TRACKBAR_INFO
*infoPtr
)
217 if (infoPtr
->lPos
== infoPtr
->lRangeMin
) return;
219 infoPtr
->lPos
-= infoPtr
->lPageSize
;
220 if (infoPtr
->lPos
< infoPtr
->lRangeMin
)
221 infoPtr
->lPos
= infoPtr
->lRangeMin
;
222 TRACKBAR_SendNotify (infoPtr
, TB_PAGEDOWN
);
226 TRACKBAR_CalcChannel (TRACKBAR_INFO
*infoPtr
)
228 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
229 INT cyChannel
, offsetthumb
, offsetedge
;
230 RECT lpRect
, *channel
= & infoPtr
->rcChannel
;
232 GetClientRect (infoPtr
->hwndSelf
, &lpRect
);
234 offsetthumb
= infoPtr
->uThumbLen
/ 4;
235 offsetedge
= offsetthumb
+ 3;
236 cyChannel
= (dwStyle
& TBS_ENABLESELRANGE
) ? offsetthumb
*3 : 4;
237 if (dwStyle
& TBS_VERT
) {
238 channel
->top
= lpRect
.top
+ offsetedge
;
239 channel
->bottom
= lpRect
.bottom
- offsetedge
;
240 if (dwStyle
& TBS_ENABLESELRANGE
)
241 channel
->left
= lpRect
.left
+ ((infoPtr
->uThumbLen
- cyChannel
+ 2) / 2);
243 channel
->left
= lpRect
.left
+ (infoPtr
->uThumbLen
/ 2) - 1;
244 if (dwStyle
& TBS_BOTH
) {
245 if (dwStyle
& TBS_NOTICKS
)
250 else if (dwStyle
& TBS_TOP
) {
251 if (dwStyle
& TBS_NOTICKS
)
256 channel
->right
= channel
->left
+ cyChannel
;
258 channel
->left
= lpRect
.left
+ offsetedge
;
259 channel
->right
= lpRect
.right
- offsetedge
;
260 if (dwStyle
& TBS_ENABLESELRANGE
)
261 channel
->top
= lpRect
.top
+ ((infoPtr
->uThumbLen
- cyChannel
+ 2) / 2);
263 channel
->top
= lpRect
.top
+ (infoPtr
->uThumbLen
/ 2) - 1;
264 if (dwStyle
& TBS_BOTH
) {
265 if (dwStyle
& TBS_NOTICKS
)
270 else if (dwStyle
& TBS_TOP
) {
271 if (dwStyle
& TBS_NOTICKS
)
276 channel
->bottom
= channel
->top
+ cyChannel
;
281 TRACKBAR_CalcThumb (TRACKBAR_INFO
*infoPtr
, LONG lPos
, RECT
*thumb
)
283 int range
, width
, height
, thumbwidth
;
284 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
287 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
288 thumbwidth
= (infoPtr
->uThumbLen
/ 2) | 1;
290 if (!range
) range
= 1;
292 GetClientRect(infoPtr
->hwndSelf
, &lpRect
);
293 if (dwStyle
& TBS_VERT
)
295 height
= infoPtr
->rcChannel
.bottom
- infoPtr
->rcChannel
.top
- thumbwidth
;
297 if ((dwStyle
& (TBS_BOTH
| TBS_LEFT
)) && !(dwStyle
& TBS_NOTICKS
))
301 thumb
->right
= thumb
->left
+ infoPtr
->uThumbLen
;
302 thumb
->top
= infoPtr
->rcChannel
.top
+
303 (height
*(lPos
- infoPtr
->lRangeMin
))/range
;
304 thumb
->bottom
= thumb
->top
+ thumbwidth
;
308 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- thumbwidth
;
310 thumb
->left
= infoPtr
->rcChannel
.left
+
311 (width
*(lPos
- infoPtr
->lRangeMin
))/range
;
312 thumb
->right
= thumb
->left
+ thumbwidth
;
313 if ((dwStyle
& (TBS_BOTH
| TBS_TOP
)) && !(dwStyle
& TBS_NOTICKS
))
317 thumb
->bottom
= thumb
->top
+ infoPtr
->uThumbLen
;
322 TRACKBAR_UpdateThumb (TRACKBAR_INFO
*infoPtr
)
324 TRACKBAR_CalcThumb(infoPtr
, infoPtr
->lPos
, &infoPtr
->rcThumb
);
328 TRACKBAR_InvalidateAll(TRACKBAR_INFO
* infoPtr
)
330 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
334 TRACKBAR_InvalidateThumb (TRACKBAR_INFO
*infoPtr
, LONG thumbPos
)
338 TRACKBAR_CalcThumb(infoPtr
, thumbPos
, &rcThumb
);
339 InflateRect(&rcThumb
, 1, 1);
340 InvalidateRect(infoPtr
->hwndSelf
, &rcThumb
, FALSE
);
344 TRACKBAR_InvalidateThumbMove (TRACKBAR_INFO
*infoPtr
, LONG oldPos
, LONG newPos
)
346 TRACKBAR_InvalidateThumb (infoPtr
, oldPos
);
347 if (newPos
!= oldPos
)
348 TRACKBAR_InvalidateThumb (infoPtr
, newPos
);
352 TRACKBAR_HasSelection (TRACKBAR_INFO
*infoPtr
)
354 return infoPtr
->lSelMin
!= infoPtr
->lSelMax
;
358 TRACKBAR_CalcSelection (TRACKBAR_INFO
*infoPtr
)
360 RECT
*selection
= &infoPtr
->rcSelection
;
361 int range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
362 int offsetthumb
, height
, width
;
365 SetRectEmpty (selection
);
367 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_VERT
) {
368 offsetthumb
= (infoPtr
->rcThumb
.bottom
- infoPtr
->rcThumb
.top
)/2;
369 height
= infoPtr
->rcChannel
.bottom
- infoPtr
->rcChannel
.top
- offsetthumb
*2;
370 selection
->top
= infoPtr
->rcChannel
.top
+ offsetthumb
+
371 (height
*infoPtr
->lSelMin
)/range
;
372 selection
->bottom
= infoPtr
->rcChannel
.top
+ offsetthumb
+
373 (height
*infoPtr
->lSelMax
)/range
;
374 selection
->left
= infoPtr
->rcChannel
.left
+ 3;
375 selection
->right
= infoPtr
->rcChannel
.right
- 3;
377 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
378 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- offsetthumb
*2;
379 selection
->left
= infoPtr
->rcChannel
.left
+ offsetthumb
+
380 (width
*infoPtr
->lSelMin
)/range
;
381 selection
->right
= infoPtr
->rcChannel
.left
+ offsetthumb
+
382 (width
*infoPtr
->lSelMax
)/range
;
383 selection
->top
= infoPtr
->rcChannel
.top
+ 3;
384 selection
->bottom
= infoPtr
->rcChannel
.bottom
- 3;
388 TRACE("selection[left=%ld, top=%ld, right=%ld, bottom=%ld]\n",
389 selection
->left
, selection
->top
, selection
->right
, selection
->bottom
);
393 TRACKBAR_AutoPage (TRACKBAR_INFO
*infoPtr
, POINT clickPoint
)
395 LONG dir
= TRACKBAR_GetAutoPageDirection(infoPtr
, clickPoint
);
396 LONG prevPos
= infoPtr
->lPos
;
398 TRACE("x=%ld, y=%ld, dir=%ld\n", clickPoint
.x
, clickPoint
.y
, dir
);
400 if (dir
> 0 && (infoPtr
->flags
& TB_AUTO_PAGE_RIGHT
))
401 TRACKBAR_PageUp(infoPtr
);
402 else if (dir
< 0 && (infoPtr
->flags
& TB_AUTO_PAGE_LEFT
))
403 TRACKBAR_PageDown(infoPtr
);
406 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
407 TRACKBAR_InvalidateThumbMove (infoPtr
, prevPos
, infoPtr
->lPos
);
412 /* Trackbar drawing code. I like my spaghetti done milanese. */
415 TRACKBAR_DrawChannel (TRACKBAR_INFO
*infoPtr
, HDC hdc
, DWORD dwStyle
)
417 RECT rcChannel
= infoPtr
->rcChannel
;
419 DrawEdge (hdc
, &rcChannel
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
420 if (dwStyle
& TBS_ENABLESELRANGE
) { /* fill the channel */
421 FillRect (hdc
, &rcChannel
, GetStockObject(WHITE_BRUSH
));
422 if (TRACKBAR_HasSelection(infoPtr
))
423 FillRect (hdc
, &infoPtr
->rcSelection
, GetSysColorBrush(COLOR_HIGHLIGHT
));
428 TRACKBAR_DrawOneTic (TRACKBAR_INFO
*infoPtr
, HDC hdc
, LONG ticPos
, int flags
)
430 int x
, y
, ox
, oy
, range
, side
, indent
= 0, len
= 3;
434 if (flags
& TBS_VERT
) {
435 offsetthumb
= (infoPtr
->rcThumb
.bottom
- infoPtr
->rcThumb
.top
)/2;
436 rcTics
.left
= infoPtr
->rcThumb
.left
- 2;
437 rcTics
.right
= infoPtr
->rcThumb
.right
+ 2;
438 rcTics
.top
= infoPtr
->rcChannel
.top
+ offsetthumb
+ 1;
439 rcTics
.bottom
= infoPtr
->rcChannel
.bottom
- offsetthumb
;
441 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
442 rcTics
.left
= infoPtr
->rcChannel
.left
+ offsetthumb
+ 1;
443 rcTics
.right
= infoPtr
->rcChannel
.right
- offsetthumb
;
444 rcTics
.top
= infoPtr
->rcThumb
.top
- 2;
445 rcTics
.bottom
= infoPtr
->rcThumb
.bottom
+ 2;
448 if (flags
& (TBS_TOP
| TBS_LEFT
)) {
458 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
460 range
= 1; /* to avoid division by zero */
462 if (flags
& TIC_SELECTIONMARK
) {
463 indent
= (flags
& TIC_SELECTIONMARKMIN
) ? -1 : 1;
464 } else if (flags
& TIC_EDGE
) {
468 if (flags
& TBS_VERT
) {
469 int height
= rcTics
.bottom
- rcTics
.top
;
470 y
= rcTics
.top
+ (height
*(ticPos
- infoPtr
->lRangeMin
))/range
;
472 int width
= rcTics
.right
- rcTics
.left
;
473 x
= rcTics
.left
+ (width
*(ticPos
- infoPtr
->lRangeMin
))/range
;
478 MoveToEx(hdc
, x
, y
, 0);
479 if (flags
& TBS_VERT
) x
+= len
* side
;
480 else y
+= len
* side
;
483 if (flags
& TIC_SELECTIONMARK
) {
484 if (flags
& TBS_VERT
) {
489 MoveToEx(hdc
, x
, y
, 0);
490 if (flags
& TBS_VERT
) {
503 TRACKBAR_DrawTic (TRACKBAR_INFO
*infoPtr
, HDC hdc
, LONG ticPos
, int flags
)
505 if ((flags
& (TBS_LEFT
| TBS_TOP
)) || (flags
& TBS_BOTH
))
506 TRACKBAR_DrawOneTic (infoPtr
, hdc
, ticPos
, flags
| TBS_LEFT
);
508 if (!(flags
& (TBS_LEFT
| TBS_TOP
)) || (flags
& TBS_BOTH
))
509 TRACKBAR_DrawOneTic (infoPtr
, hdc
, ticPos
, flags
& ~TBS_LEFT
);
513 TRACKBAR_DrawTics (TRACKBAR_INFO
*infoPtr
, HDC hdc
, DWORD dwStyle
)
515 int i
, ticFlags
= dwStyle
& 0x0f;
516 LOGPEN ticPen
= { PS_SOLID
, {1, 0}, GetSysColor (COLOR_3DDKSHADOW
) };
517 HPEN hOldPen
, hTicPen
;
519 /* create the pen to draw the tics with */
520 hTicPen
= CreatePenIndirect(&ticPen
);
521 hOldPen
= hTicPen
? SelectObject(hdc
, hTicPen
) : 0;
523 /* actually draw the tics */
524 for (i
=0; i
<infoPtr
->uNumTics
; i
++)
525 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->tics
[i
], ticFlags
);
527 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lRangeMin
, ticFlags
| TIC_EDGE
);
528 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lRangeMax
, ticFlags
| TIC_EDGE
);
530 if ((dwStyle
& TBS_ENABLESELRANGE
) && TRACKBAR_HasSelection(infoPtr
)) {
531 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lSelMin
,
532 ticFlags
| TIC_SELECTIONMARKMIN
);
533 TRACKBAR_DrawTic (infoPtr
, hdc
, infoPtr
->lSelMax
,
534 ticFlags
| TIC_SELECTIONMARKMAX
);
537 /* clean up the pen, if we created one */
539 SelectObject(hdc
, hOldPen
);
540 DeleteObject(hTicPen
);
545 TRACKBAR_DrawThumb(TRACKBAR_INFO
*infoPtr
, HDC hdc
, DWORD dwStyle
)
549 RECT thumb
= infoPtr
->rcThumb
;
556 fillClr
= infoPtr
->flags
& TB_DRAG_MODE
? COLOR_BTNHILIGHT
: COLOR_BTNFACE
;
557 oldbr
= SelectObject (hdc
, GetSysColorBrush(fillClr
));
558 SetPolyFillMode (hdc
, WINDING
);
560 if (dwStyle
& TBS_BOTH
)
562 points
[0].x
=thumb
.right
;
563 points
[0].y
=thumb
.top
;
564 points
[1].x
=thumb
.right
;
565 points
[1].y
=thumb
.bottom
;
566 points
[2].x
=thumb
.left
;
567 points
[2].y
=thumb
.bottom
;
568 points
[3].x
=thumb
.left
;
569 points
[3].y
=thumb
.top
;
570 points
[4].x
=points
[0].x
;
571 points
[4].y
=points
[0].y
;
577 if (dwStyle
& TBS_VERT
)
579 PointDepth
= (thumb
.bottom
- thumb
.top
) / 2;
580 if (dwStyle
& TBS_LEFT
)
582 points
[0].x
=thumb
.right
;
583 points
[0].y
=thumb
.top
;
584 points
[1].x
=thumb
.right
;
585 points
[1].y
=thumb
.bottom
;
586 points
[2].x
=thumb
.left
+ PointDepth
;
587 points
[2].y
=thumb
.bottom
;
588 points
[3].x
=thumb
.left
;
589 points
[3].y
=(thumb
.bottom
- thumb
.top
) / 2 + thumb
.top
+ 1;
590 points
[4].x
=thumb
.left
+ PointDepth
;
591 points
[4].y
=thumb
.top
;
592 points
[5].x
=points
[0].x
;
593 points
[5].y
=points
[0].y
;
598 points
[0].x
=thumb
.right
;
599 points
[0].y
=(thumb
.bottom
- thumb
.top
) / 2 + thumb
.top
+ 1;
600 points
[1].x
=thumb
.right
- PointDepth
;
601 points
[1].y
=thumb
.bottom
;
602 points
[2].x
=thumb
.left
;
603 points
[2].y
=thumb
.bottom
;
604 points
[3].x
=thumb
.left
;
605 points
[3].y
=thumb
.top
;
606 points
[4].x
=thumb
.right
- PointDepth
;
607 points
[4].y
=thumb
.top
;
608 points
[5].x
=points
[0].x
;
609 points
[5].y
=points
[0].y
;
614 PointDepth
= (thumb
.right
- thumb
.left
) / 2;
615 if (dwStyle
& TBS_TOP
)
617 points
[0].x
=(thumb
.right
- thumb
.left
) / 2 + thumb
.left
+ 1;
618 points
[0].y
=thumb
.top
;
619 points
[1].x
=thumb
.right
;
620 points
[1].y
=thumb
.top
+ PointDepth
;
621 points
[2].x
=thumb
.right
;
622 points
[2].y
=thumb
.bottom
;
623 points
[3].x
=thumb
.left
;
624 points
[3].y
=thumb
.bottom
;
625 points
[4].x
=thumb
.left
;
626 points
[4].y
=thumb
.top
+ PointDepth
;
627 points
[5].x
=points
[0].x
;
628 points
[5].y
=points
[0].y
;
633 points
[0].x
=thumb
.right
;
634 points
[0].y
=thumb
.top
;
635 points
[1].x
=thumb
.right
;
636 points
[1].y
=thumb
.bottom
- PointDepth
;
637 points
[2].x
=(thumb
.right
- thumb
.left
) / 2 + thumb
.left
+ 1;
638 points
[2].y
=thumb
.bottom
;
639 points
[3].x
=thumb
.left
;
640 points
[3].y
=thumb
.bottom
- PointDepth
;
641 points
[4].x
=thumb
.left
;
642 points
[4].y
=thumb
.top
;
643 points
[5].x
=points
[0].x
;
644 points
[5].y
=points
[0].y
;
650 /* Draw the thumb now */
651 Polygon (hdc
, points
, PointCount
);
652 oldpen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
653 Polyline(hdc
,points
, BlackUntil
);
654 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
655 Polyline(hdc
, &points
[BlackUntil
-1], PointCount
+1-BlackUntil
);
656 SelectObject(hdc
, oldpen
);
657 SelectObject(hdc
, oldbr
);
662 TRACKBAR_ActivateToolTip (TRACKBAR_INFO
*infoPtr
, BOOL fShow
)
666 if (!infoPtr
->hwndToolTip
) return;
668 ZeroMemory(&ti
, sizeof(ti
));
669 ti
.cbSize
= sizeof(ti
);
670 ti
.hwnd
= infoPtr
->hwndSelf
;
672 SendMessageW (infoPtr
->hwndToolTip
, TTM_TRACKACTIVATE
, fShow
, (LPARAM
)&ti
);
677 TRACKBAR_UpdateToolTip (TRACKBAR_INFO
*infoPtr
)
679 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
680 WCHAR buf
[80], fmt
[] = { '%', 'l', 'd', 0 };
686 if (!infoPtr
->hwndToolTip
) return;
688 ZeroMemory(&ti
, sizeof(ti
));
689 ti
.cbSize
= sizeof(ti
);
690 ti
.hwnd
= infoPtr
->hwndSelf
;
691 ti
.uFlags
= TTF_IDISHWND
| TTF_TRACK
| TTF_ABSOLUTE
;
693 wsprintfW (buf
, fmt
, infoPtr
->lPos
);
695 SendMessageW (infoPtr
->hwndToolTip
, TTM_UPDATETIPTEXTW
, 0, (LPARAM
)&ti
);
697 GetClientRect (infoPtr
->hwndSelf
, &rcClient
);
698 size
= SendMessageW (infoPtr
->hwndToolTip
, TTM_GETBUBBLESIZE
, 0, (LPARAM
)&ti
);
699 if (dwStyle
& TBS_VERT
) {
700 if (infoPtr
->fLocation
== TBTS_LEFT
)
701 pt
.x
= 0 - LOWORD(size
) - TOOLTIP_OFFSET
;
703 pt
.x
= rcClient
.right
+ TOOLTIP_OFFSET
;
704 pt
.y
= (infoPtr
->rcThumb
.top
+ infoPtr
->rcThumb
.bottom
- HIWORD(size
))/2;
706 if (infoPtr
->fLocation
== TBTS_TOP
)
707 pt
.y
= 0 - HIWORD(size
) - TOOLTIP_OFFSET
;
709 pt
.y
= rcClient
.bottom
+ TOOLTIP_OFFSET
;
710 pt
.x
= (infoPtr
->rcThumb
.left
+ infoPtr
->rcThumb
.right
- LOWORD(size
))/2;
712 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
714 SendMessageW (infoPtr
->hwndToolTip
, TTM_TRACKPOSITION
,
715 0, (LPARAM
)MAKELPARAM(pt
.x
, pt
.y
));
720 TRACKBAR_Refresh (TRACKBAR_INFO
*infoPtr
, HDC hdcDst
)
722 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
725 HBITMAP hOldBmp
= 0, hOffScreenBmp
= 0;
729 if (infoPtr
->flags
& TB_THUMBCHANGED
) {
730 TRACKBAR_UpdateThumb (infoPtr
);
731 if (infoPtr
->flags
& TB_THUMBSIZECHANGED
)
732 TRACKBAR_CalcChannel (infoPtr
);
734 if (infoPtr
->flags
& TB_SELECTIONCHANGED
)
735 TRACKBAR_CalcSelection (infoPtr
);
737 if (infoPtr
->flags
& TB_DRAG_MODE
)
738 TRACKBAR_UpdateToolTip (infoPtr
);
740 infoPtr
->flags
&= ~ (TB_THUMBCHANGED
| TB_SELECTIONCHANGED
);
742 GetClientRect (infoPtr
->hwndSelf
, &rcClient
);
744 /* try to render offscreen, if we fail, carrry onscreen */
745 hdc
= CreateCompatibleDC(hdcDst
);
747 hOffScreenBmp
= CreateCompatibleBitmap(hdcDst
, rcClient
.right
, rcClient
.bottom
);
749 hOldBmp
= SelectObject(hdc
, hOffScreenBmp
);
758 ZeroMemory(&nmcd
, sizeof(nmcd
));
759 nmcd
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
760 nmcd
.hdr
.idFrom
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_ID
);
761 nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
764 /* start the paint cycle */
766 gcdrf
= notify_customdraw(&nmcd
, CDDS_PREPAINT
);
767 if (gcdrf
& CDRF_SKIPDEFAULT
) goto cleanup
;
769 /* Erase backbround */
770 if (gcdrf
== CDRF_DODEFAULT
||
771 notify_customdraw(&nmcd
, CDDS_PREERASE
) != CDRF_SKIPDEFAULT
) {
772 FillRect (hdc
, &rcClient
, GetSysColorBrush(COLOR_BTNFACE
));
773 if (gcdrf
!= CDRF_DODEFAULT
)
774 notify_customdraw(&nmcd
, CDDS_POSTERASE
);
778 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
779 nmcd
.dwItemSpec
= TBCD_CHANNEL
;
780 nmcd
.uItemState
= CDIS_DEFAULT
;
781 nmcd
.rc
= infoPtr
->rcChannel
;
782 icdrf
= notify_customdraw(&nmcd
, CDDS_ITEMPREPAINT
);
783 } else icdrf
= CDRF_DODEFAULT
;
784 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
785 TRACKBAR_DrawChannel (infoPtr
, hdc
, dwStyle
);
786 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
787 notify_customdraw(&nmcd
, CDDS_ITEMPOSTPAINT
);
792 if (!(dwStyle
& TBS_NOTICKS
)) {
793 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
794 nmcd
.dwItemSpec
= TBCD_TICS
;
795 nmcd
.uItemState
= CDIS_DEFAULT
;
797 icdrf
= notify_customdraw(&nmcd
, CDDS_ITEMPREPAINT
);
798 } else icdrf
= CDRF_DODEFAULT
;
799 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
800 TRACKBAR_DrawTics (infoPtr
, hdc
, dwStyle
);
801 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
802 notify_customdraw(&nmcd
, CDDS_ITEMPOSTPAINT
);
807 if (!(dwStyle
& TBS_NOTHUMB
)) {
808 if (gcdrf
& CDRF_NOTIFYITEMDRAW
) {
809 nmcd
.dwItemSpec
= TBCD_THUMB
;
810 nmcd
.uItemState
= infoPtr
->flags
& TB_DRAG_MODE
? CDIS_HOT
: CDIS_DEFAULT
;
811 nmcd
.rc
= infoPtr
->rcThumb
;
812 icdrf
= notify_customdraw(&nmcd
, CDDS_ITEMPREPAINT
);
813 } else icdrf
= CDRF_DODEFAULT
;
814 if ( !(icdrf
& CDRF_SKIPDEFAULT
) ) {
815 TRACKBAR_DrawThumb(infoPtr
, hdc
, dwStyle
);
816 if (icdrf
& CDRF_NOTIFYPOSTPAINT
)
817 notify_customdraw(&nmcd
, CDDS_ITEMPOSTPAINT
);
821 /* draw focus rectangle */
822 if (infoPtr
->bFocussed
) {
823 DrawFocusRect(hdc
, &rcClient
);
826 /* finish up the painting */
827 if (gcdrf
& CDRF_NOTIFYPOSTPAINT
)
828 notify_customdraw(&nmcd
, CDDS_POSTPAINT
);
831 /* cleanup, if we rendered offscreen */
833 BitBlt(hdcDst
, 0, 0, rcClient
.right
, rcClient
.bottom
, hdc
, 0, 0, SRCCOPY
);
834 SelectObject(hdc
, hOldBmp
);
835 DeleteObject(hOffScreenBmp
);
842 TRACKBAR_AlignBuddies (TRACKBAR_INFO
*infoPtr
)
844 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
845 HWND hwndParent
= GetParent (infoPtr
->hwndSelf
);
846 RECT rcSelf
, rcBuddy
;
849 GetWindowRect (infoPtr
->hwndSelf
, &rcSelf
);
850 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcSelf
, 2);
852 /* align buddy left or above */
853 if (infoPtr
->hwndBuddyLA
) {
854 GetWindowRect (infoPtr
->hwndBuddyLA
, &rcBuddy
);
855 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcBuddy
, 2);
857 if (dwStyle
& TBS_VERT
) {
858 x
= (infoPtr
->rcChannel
.right
+ infoPtr
->rcChannel
.left
) / 2 -
859 (rcBuddy
.right
- rcBuddy
.left
) / 2 + rcSelf
.left
;
860 y
= rcSelf
.top
- (rcBuddy
.bottom
- rcBuddy
.top
);
863 x
= rcSelf
.left
- (rcBuddy
.right
- rcBuddy
.left
);
864 y
= (infoPtr
->rcChannel
.bottom
+ infoPtr
->rcChannel
.top
) / 2 -
865 (rcBuddy
.bottom
- rcBuddy
.top
) / 2 + rcSelf
.top
;
868 SetWindowPos (infoPtr
->hwndBuddyLA
, 0, x
, y
, 0, 0,
869 SWP_NOZORDER
| SWP_NOSIZE
);
873 /* align buddy right or below */
874 if (infoPtr
->hwndBuddyRB
) {
875 GetWindowRect (infoPtr
->hwndBuddyRB
, &rcBuddy
);
876 MapWindowPoints (HWND_DESKTOP
, hwndParent
, (LPPOINT
)&rcBuddy
, 2);
878 if (dwStyle
& TBS_VERT
) {
879 x
= (infoPtr
->rcChannel
.right
+ infoPtr
->rcChannel
.left
) / 2 -
880 (rcBuddy
.right
- rcBuddy
.left
) / 2 + rcSelf
.left
;
885 y
= (infoPtr
->rcChannel
.bottom
+ infoPtr
->rcChannel
.top
) / 2 -
886 (rcBuddy
.bottom
- rcBuddy
.top
) / 2 + rcSelf
.top
;
888 SetWindowPos (infoPtr
->hwndBuddyRB
, 0, x
, y
, 0, 0,
889 SWP_NOZORDER
| SWP_NOSIZE
);
895 TRACKBAR_ClearSel (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
)
897 infoPtr
->lSelMin
= 0;
898 infoPtr
->lSelMax
= 0;
899 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
901 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
908 TRACKBAR_ClearTics (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
)
911 COMCTL32_Free (infoPtr
->tics
);
912 infoPtr
->tics
= NULL
;
913 infoPtr
->uNumTics
= 0;
916 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
922 static LRESULT
inline
923 TRACKBAR_GetChannelRect (TRACKBAR_INFO
*infoPtr
, LPRECT lprc
)
925 if (lprc
== NULL
) return 0;
927 lprc
->left
= infoPtr
->rcChannel
.left
;
928 lprc
->right
= infoPtr
->rcChannel
.right
;
929 lprc
->bottom
= infoPtr
->rcChannel
.bottom
;
930 lprc
->top
= infoPtr
->rcChannel
.top
;
937 TRACKBAR_GetNumTics (TRACKBAR_INFO
*infoPtr
)
939 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_NOTICKS
)
942 return infoPtr
->uNumTics
+ 2;
946 static int comp_tics(const void *ap
, const void *bp
)
948 DWORD a
= *((DWORD
*)ap
);
949 DWORD b
= *((DWORD
*)bp
);
951 TRACE("(a=%ld, b=%ld)\n", a
, b
);
952 if (a
< b
) return -1;
959 TRACKBAR_GetTic (TRACKBAR_INFO
*infoPtr
, INT iTic
)
961 if ((iTic
< 0) || (iTic
>= infoPtr
->uNumTics
) || !infoPtr
->tics
)
964 qsort(infoPtr
->tics
, infoPtr
->uNumTics
, sizeof(DWORD
), comp_tics
);
965 return infoPtr
->tics
[iTic
];
970 TRACKBAR_GetTicPos (TRACKBAR_INFO
*infoPtr
, INT iTic
)
972 LONG range
, width
, pos
, tic
;
975 if ((iTic
< 0) || (iTic
>= infoPtr
->uNumTics
) || !infoPtr
->tics
)
978 tic
= TRACKBAR_GetTic (infoPtr
, iTic
);
979 range
= infoPtr
->lRangeMax
- infoPtr
->lRangeMin
;
980 if (range
<= 0) range
= 1;
981 offsetthumb
= (infoPtr
->rcThumb
.right
- infoPtr
->rcThumb
.left
)/2;
982 width
= infoPtr
->rcChannel
.right
- infoPtr
->rcChannel
.left
- offsetthumb
*2;
983 pos
= infoPtr
->rcChannel
.left
+ offsetthumb
+ (width
* tic
) / range
;
990 TRACKBAR_SetBuddy (TRACKBAR_INFO
*infoPtr
, BOOL fLocation
, HWND hwndBuddy
)
995 /* buddy is left or above */
996 hwndTemp
= infoPtr
->hwndBuddyLA
;
997 infoPtr
->hwndBuddyLA
= hwndBuddy
;
1000 /* buddy is right or below */
1001 hwndTemp
= infoPtr
->hwndBuddyRB
;
1002 infoPtr
->hwndBuddyRB
= hwndBuddy
;
1005 TRACKBAR_AlignBuddies (infoPtr
);
1012 TRACKBAR_SetLineSize (TRACKBAR_INFO
*infoPtr
, LONG lLineSize
)
1014 LONG lTemp
= infoPtr
->lLineSize
;
1016 infoPtr
->lLineSize
= lLineSize
;
1023 TRACKBAR_SetPageSize (TRACKBAR_INFO
*infoPtr
, LONG lPageSize
)
1025 LONG lTemp
= infoPtr
->lPageSize
;
1027 infoPtr
->lPageSize
= lPageSize
;
1033 static LRESULT
inline
1034 TRACKBAR_SetPos (TRACKBAR_INFO
*infoPtr
, BOOL fPosition
, LONG lPosition
)
1036 LONG oldPos
= infoPtr
->lPos
;
1037 infoPtr
->lPos
= lPosition
;
1039 if (infoPtr
->lPos
< infoPtr
->lRangeMin
)
1040 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1042 if (infoPtr
->lPos
> infoPtr
->lRangeMax
)
1043 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1044 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1046 if (fPosition
) TRACKBAR_InvalidateThumbMove(infoPtr
, oldPos
, lPosition
);
1052 static LRESULT
inline
1053 TRACKBAR_SetRange (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lRange
)
1055 infoPtr
->lRangeMin
= (SHORT
)LOWORD(lRange
);
1056 infoPtr
->lRangeMax
= (SHORT
)HIWORD(lRange
);
1058 if (infoPtr
->lPos
< infoPtr
->lRangeMin
) {
1059 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1060 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1063 if (infoPtr
->lPos
> infoPtr
->lRangeMax
) {
1064 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1065 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1068 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1069 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1071 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1077 static LRESULT
inline
1078 TRACKBAR_SetRangeMax (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lMax
)
1080 infoPtr
->lRangeMax
= lMax
;
1081 if (infoPtr
->lPos
> infoPtr
->lRangeMax
) {
1082 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1083 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1086 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1087 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1089 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1095 static LRESULT
inline
1096 TRACKBAR_SetRangeMin (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lMin
)
1098 infoPtr
->lRangeMin
= lMin
;
1099 if (infoPtr
->lPos
< infoPtr
->lRangeMin
) {
1100 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1101 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1104 infoPtr
->lPageSize
= (infoPtr
->lRangeMax
- infoPtr
->lRangeMin
) / 5;
1105 if (infoPtr
->lPageSize
== 0) infoPtr
->lPageSize
= 1;
1107 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1113 static LRESULT
inline
1114 TRACKBAR_SetSel (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lSel
)
1116 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1119 infoPtr
->lSelMin
= (SHORT
)LOWORD(lSel
);
1120 infoPtr
->lSelMax
= (SHORT
)HIWORD(lSel
);
1121 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
1123 if (infoPtr
->lSelMin
< infoPtr
->lRangeMin
)
1124 infoPtr
->lSelMin
= infoPtr
->lRangeMin
;
1125 if (infoPtr
->lSelMax
> infoPtr
->lRangeMax
)
1126 infoPtr
->lSelMax
= infoPtr
->lRangeMax
;
1128 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1134 static LRESULT
inline
1135 TRACKBAR_SetSelEnd (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lEnd
)
1137 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1140 infoPtr
->lSelMax
= lEnd
;
1141 infoPtr
->flags
|= TB_SELECTIONCHANGED
;
1143 if (infoPtr
->lSelMax
> infoPtr
->lRangeMax
)
1144 infoPtr
->lSelMax
= infoPtr
->lRangeMax
;
1146 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1152 static LRESULT
inline
1153 TRACKBAR_SetSelStart (TRACKBAR_INFO
*infoPtr
, BOOL fRedraw
, LONG lStart
)
1155 if (!GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_ENABLESELRANGE
)
1158 infoPtr
->lSelMin
= lStart
;
1159 infoPtr
->flags
|=TB_SELECTIONCHANGED
;
1161 if (infoPtr
->lSelMin
< infoPtr
->lRangeMin
)
1162 infoPtr
->lSelMin
= infoPtr
->lRangeMin
;
1164 if (fRedraw
) TRACKBAR_InvalidateAll(infoPtr
);
1170 static LRESULT
inline
1171 TRACKBAR_SetThumbLength (TRACKBAR_INFO
*infoPtr
, UINT iLength
)
1173 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_FIXEDLENGTH
) {
1174 infoPtr
->uThumbLen
= iLength
;
1175 infoPtr
->flags
|= TB_THUMBSIZECHANGED
;
1176 InvalidateRect (infoPtr
->hwndSelf
, &infoPtr
->rcThumb
, FALSE
);
1183 static LRESULT
inline
1184 TRACKBAR_SetTic (TRACKBAR_INFO
*infoPtr
, LONG lPos
)
1186 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_AUTOTICKS
)
1189 if ((lPos
< infoPtr
->lRangeMin
) || (lPos
> infoPtr
->lRangeMax
))
1192 TRACE("lPos=%ld\n", lPos
);
1194 infoPtr
->uNumTics
++;
1195 infoPtr
->tics
=COMCTL32_ReAlloc( infoPtr
->tics
,
1196 (infoPtr
->uNumTics
)*sizeof (DWORD
));
1197 if (!infoPtr
->tics
) {
1198 infoPtr
->uNumTics
= 0;
1199 TRACKBAR_SendNotify(infoPtr
, NM_OUTOFMEMORY
);
1202 infoPtr
->tics
[infoPtr
->uNumTics
-1] = lPos
;
1204 TRACKBAR_InvalidateAll(infoPtr
);
1210 static LRESULT
inline
1211 TRACKBAR_SetTicFreq (TRACKBAR_INFO
*infoPtr
, WORD wFreq
)
1213 if (GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_AUTOTICKS
) {
1214 infoPtr
->uTicFreq
= wFreq
;
1215 TRACKBAR_RecalculateTics (infoPtr
);
1216 TRACKBAR_InvalidateAll(infoPtr
);
1224 TRACKBAR_SetTipSide (TRACKBAR_INFO
*infoPtr
, INT fLocation
)
1226 INT fTemp
= infoPtr
->fLocation
;
1228 infoPtr
->fLocation
= fLocation
;
1234 static LRESULT
inline
1235 TRACKBAR_SetToolTips (TRACKBAR_INFO
*infoPtr
, HWND hwndTT
)
1237 infoPtr
->hwndToolTip
= hwndTT
;
1244 TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO
*infoPtr
, BOOL fUnicode
)
1246 BOOL bTemp
= infoPtr
->bUnicode
;
1248 infoPtr
->bUnicode
= fUnicode
;
1255 TRACKBAR_InitializeThumb (TRACKBAR_INFO
*infoPtr
)
1257 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1259 int clientWidth
, clientMetric
;
1261 /* initial thumb length */
1262 clientMetric
= (dwStyle
& TBS_ENABLESELRANGE
) ? 23 : 21;
1263 GetClientRect(infoPtr
->hwndSelf
,&rect
);
1264 if (dwStyle
& TBS_VERT
) {
1265 clientWidth
= rect
.right
- rect
.left
;
1267 clientWidth
= rect
.bottom
- rect
.top
;
1269 if (clientWidth
>= clientMetric
)
1270 infoPtr
->uThumbLen
= clientMetric
;
1272 infoPtr
->uThumbLen
= clientWidth
> 9 ? clientWidth
- 6 : 4;
1274 TRACKBAR_CalcChannel (infoPtr
);
1275 TRACKBAR_UpdateThumb (infoPtr
);
1276 infoPtr
->flags
&= ~TB_SELECTIONCHANGED
;
1283 TRACKBAR_Create (HWND hwnd
, LPCREATESTRUCTW lpcs
)
1285 TRACKBAR_INFO
*infoPtr
;
1286 DWORD oldStyle
, newStyle
;
1288 infoPtr
= (TRACKBAR_INFO
*)COMCTL32_Alloc (sizeof(TRACKBAR_INFO
));
1289 if (!infoPtr
) return -1;
1290 SetWindowLongW (hwnd
, 0, (DWORD
)infoPtr
);
1292 /* set default values */
1293 infoPtr
->hwndSelf
= hwnd
;
1294 infoPtr
->lRangeMin
= 0;
1295 infoPtr
->lRangeMax
= 100;
1296 infoPtr
->lLineSize
= 1;
1297 infoPtr
->lPageSize
= 20;
1298 infoPtr
->lSelMin
= 0;
1299 infoPtr
->lSelMax
= 0;
1301 infoPtr
->fLocation
= -1;
1302 infoPtr
->uNumTics
= 0; /* start and end tic are not included in count*/
1303 infoPtr
->uTicFreq
= 1;
1304 infoPtr
->tics
= NULL
;
1305 infoPtr
->hwndNotify
= GetParent (hwnd
);
1307 TRACKBAR_InitializeThumb (infoPtr
);
1309 oldStyle
= newStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1310 if (oldStyle
& TBS_VERT
) {
1311 if (! (oldStyle
& (TBS_LEFT
| TBS_RIGHT
| TBS_BOTH
)) )
1312 newStyle
|= TBS_RIGHT
;
1314 if (! (oldStyle
& (TBS_TOP
| TBS_BOTTOM
| TBS_BOTH
)) )
1315 newStyle
|= TBS_BOTTOM
;
1317 if (newStyle
!= oldStyle
)
1318 SetWindowLongW (hwnd
, GWL_STYLE
, newStyle
);
1320 /* Create tooltip control */
1321 if (newStyle
& TBS_TOOLTIPS
) {
1323 infoPtr
->hwndToolTip
=
1324 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, 0,
1325 CW_USEDEFAULT
, CW_USEDEFAULT
,
1326 CW_USEDEFAULT
, CW_USEDEFAULT
,
1329 if (infoPtr
->hwndToolTip
) {
1331 ZeroMemory (&ti
, sizeof(ti
));
1332 ti
.cbSize
= sizeof(ti
);
1333 ti
.uFlags
= TTF_IDISHWND
| TTF_TRACK
| TTF_ABSOLUTE
;
1336 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
, 0, (LPARAM
)&ti
);
1345 TRACKBAR_Destroy (TRACKBAR_INFO
*infoPtr
)
1347 /* delete tooltip control */
1348 if (infoPtr
->hwndToolTip
)
1349 DestroyWindow (infoPtr
->hwndToolTip
);
1351 COMCTL32_Free (infoPtr
);
1352 SetWindowLongW (infoPtr
->hwndSelf
, 0, 0);
1358 TRACKBAR_KillFocus (TRACKBAR_INFO
*infoPtr
, HWND hwndGetFocus
)
1361 infoPtr
->bFocussed
= FALSE
;
1362 TRACKBAR_InvalidateAll(infoPtr
);
1368 TRACKBAR_LButtonDown (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, POINTS pts
)
1370 POINT clickPoint
= { pts
.x
, pts
.y
};
1372 SetFocus(infoPtr
->hwndSelf
);
1374 if (PtInRect(&infoPtr
->rcThumb
, clickPoint
)) {
1375 infoPtr
->flags
|= TB_DRAG_MODE
;
1376 SetCapture (infoPtr
->hwndSelf
);
1377 TRACKBAR_UpdateToolTip (infoPtr
);
1378 TRACKBAR_ActivateToolTip (infoPtr
, TRUE
);
1379 TRACKBAR_InvalidateThumb(infoPtr
, infoPtr
->lPos
);
1381 LONG dir
= TRACKBAR_GetAutoPageDirection(infoPtr
, clickPoint
);
1382 if (dir
== 0) return 0;
1383 infoPtr
->flags
|= (dir
< 0) ? TB_AUTO_PAGE_LEFT
: TB_AUTO_PAGE_RIGHT
;
1384 TRACKBAR_AutoPage (infoPtr
, clickPoint
);
1385 SetCapture (infoPtr
->hwndSelf
);
1386 SetTimer(infoPtr
->hwndSelf
, TB_REFRESH_TIMER
, TB_REFRESH_DELAY
, 0);
1394 TRACKBAR_LButtonUp (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, POINTS pts
)
1396 if (infoPtr
->flags
& TB_DRAG_MODE
) {
1397 TRACKBAR_SendNotify (infoPtr
, TB_ENDTRACK
);
1398 infoPtr
->flags
&= ~TB_DRAG_MODE
;
1400 TRACKBAR_SendNotify(infoPtr
, NM_RELEASEDCAPTURE
);
1401 TRACKBAR_ActivateToolTip(infoPtr
, FALSE
);
1402 TRACKBAR_InvalidateThumb(infoPtr
, infoPtr
->lPos
);
1404 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1405 KillTimer (infoPtr
->hwndSelf
, TB_REFRESH_TIMER
);
1406 infoPtr
->flags
&= ~TB_AUTO_PAGE
;
1408 TRACKBAR_SendNotify(infoPtr
, NM_RELEASEDCAPTURE
);
1416 TRACKBAR_CaptureChanged (TRACKBAR_INFO
*infoPtr
)
1418 TRACKBAR_SendNotify (infoPtr
, TB_ENDTRACK
);
1424 TRACKBAR_Paint (TRACKBAR_INFO
*infoPtr
, HDC hdc
)
1427 TRACKBAR_Refresh(infoPtr
, hdc
);
1430 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1431 TRACKBAR_Refresh (infoPtr
, hdc
);
1432 EndPaint (infoPtr
->hwndSelf
, &ps
);
1440 TRACKBAR_SetFocus (TRACKBAR_INFO
*infoPtr
, HWND hwndLoseFocus
)
1443 infoPtr
->bFocussed
= TRUE
;
1444 TRACKBAR_InvalidateAll(infoPtr
);
1451 TRACKBAR_Size (TRACKBAR_INFO
*infoPtr
, DWORD fwSizeType
, INT nWidth
, INT nHeight
)
1453 TRACKBAR_CalcChannel (infoPtr
);
1454 TRACKBAR_AlignBuddies (infoPtr
);
1461 TRACKBAR_Timer (TRACKBAR_INFO
*infoPtr
, INT wTimerID
, TIMERPROC
*tmrpc
)
1463 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1465 if (GetCursorPos(&pt
))
1466 if (ScreenToClient(infoPtr
->hwndSelf
, &pt
))
1467 TRACKBAR_AutoPage(infoPtr
, pt
);
1474 TRACKBAR_SendNotify (TRACKBAR_INFO
*infoPtr
, UINT code
)
1476 BOOL bVert
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_VERT
;
1478 TRACE("%x\n", code
);
1480 return (BOOL
) SendMessageW (GetParent (infoPtr
->hwndSelf
),
1481 bVert
? WM_VSCROLL
: WM_HSCROLL
,
1482 (WPARAM
)code
, (LPARAM
)infoPtr
->hwndSelf
);
1487 TRACKBAR_MouseMove (TRACKBAR_INFO
*infoPtr
, DWORD fwKeys
, POINTS pts
)
1489 DWORD dwStyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
);
1490 INT clickPlace
= (dwStyle
& TBS_VERT
) ? pts
.y
: pts
.x
;
1491 LONG dragPos
, oldPos
= infoPtr
->lPos
;
1493 TRACE("(x=%d. y=%d)\n", pts
.x
, pts
.y
);
1495 if (infoPtr
->flags
& TB_AUTO_PAGE
) {
1497 POINTSTOPOINT(pt
, pts
);
1498 TRACKBAR_AutoPage (infoPtr
, pt
);
1502 if (!(infoPtr
->flags
& TB_DRAG_MODE
)) return TRUE
;
1504 dragPos
= TRACKBAR_ConvertPlaceToPosition (infoPtr
, clickPlace
,
1505 dwStyle
& TBS_VERT
);
1506 if (dragPos
== oldPos
) return TRUE
;
1508 infoPtr
->lPos
= dragPos
;
1510 infoPtr
->flags
|= TB_THUMBPOSCHANGED
;
1511 TRACKBAR_SendNotify (infoPtr
, TB_THUMBTRACK
| (infoPtr
->lPos
<<16));
1514 TRACKBAR_InvalidateThumbMove(infoPtr
, oldPos
, dragPos
);
1515 UpdateWindow (infoPtr
->hwndSelf
);
1522 TRACKBAR_KeyDown (TRACKBAR_INFO
*infoPtr
, INT nVirtKey
, DWORD lKeyData
)
1524 BOOL downIsLeft
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_STYLE
) & TBS_DOWNISLEFT
;
1525 LONG pos
= infoPtr
->lPos
;
1527 TRACE("%x\n", nVirtKey
);
1531 if (downIsLeft
) goto step_right
;
1534 if (infoPtr
->lPos
== infoPtr
->lRangeMin
) return FALSE
;
1535 infoPtr
->lPos
-= infoPtr
->lLineSize
;
1536 if (infoPtr
->lPos
< infoPtr
->lRangeMin
)
1537 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1538 TRACKBAR_SendNotify (infoPtr
, TB_LINEUP
);
1541 if (downIsLeft
) goto step_left
;
1544 if (infoPtr
->lPos
== infoPtr
->lRangeMax
) return FALSE
;
1545 infoPtr
->lPos
+= infoPtr
->lLineSize
;
1546 if (infoPtr
->lPos
> infoPtr
->lRangeMax
)
1547 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1548 TRACKBAR_SendNotify (infoPtr
, TB_LINEDOWN
);
1551 if (downIsLeft
) goto page_left
;
1553 TRACKBAR_PageUp(infoPtr
);
1556 if (downIsLeft
) goto page_right
;
1558 TRACKBAR_PageDown(infoPtr
);
1561 if (infoPtr
->lPos
== infoPtr
->lRangeMin
) return FALSE
;
1562 infoPtr
->lPos
= infoPtr
->lRangeMin
;
1563 TRACKBAR_SendNotify (infoPtr
, TB_TOP
);
1566 if (infoPtr
->lPos
== infoPtr
->lRangeMax
) return FALSE
;
1567 infoPtr
->lPos
= infoPtr
->lRangeMax
;
1568 TRACKBAR_SendNotify (infoPtr
, TB_BOTTOM
);
1572 if (pos
!= infoPtr
->lPos
) {
1573 infoPtr
->flags
|=TB_THUMBPOSCHANGED
;
1574 TRACKBAR_InvalidateThumbMove (infoPtr
, pos
, infoPtr
->lPos
);
1582 TRACKBAR_KeyUp (TRACKBAR_INFO
*infoPtr
, INT nVirtKey
, DWORD lKeyData
)
1593 TRACKBAR_SendNotify (infoPtr
, TB_ENDTRACK
);
1599 static LRESULT WINAPI
1600 TRACKBAR_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1602 TRACKBAR_INFO
*infoPtr
= (TRACKBAR_INFO
*)GetWindowLongW (hwnd
, 0);
1604 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
1606 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1607 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1612 return TRACKBAR_ClearSel (infoPtr
, (BOOL
)wParam
);
1615 return TRACKBAR_ClearTics (infoPtr
, (BOOL
)wParam
);
1618 return (LRESULT
)(wParam
? infoPtr
->hwndBuddyLA
: infoPtr
->hwndBuddyRB
);
1620 case TBM_GETCHANNELRECT
:
1621 return TRACKBAR_GetChannelRect (infoPtr
, (LPRECT
)lParam
);
1623 case TBM_GETLINESIZE
:
1624 return infoPtr
->lLineSize
;
1626 case TBM_GETNUMTICS
:
1627 return TRACKBAR_GetNumTics (infoPtr
);
1629 case TBM_GETPAGESIZE
:
1630 return infoPtr
->lPageSize
;
1633 return infoPtr
->lPos
;
1636 return (LRESULT
)infoPtr
->tics
;
1638 case TBM_GETRANGEMAX
:
1639 return infoPtr
->lRangeMax
;
1641 case TBM_GETRANGEMIN
:
1642 return infoPtr
->lRangeMin
;
1645 return infoPtr
->lSelMax
;
1647 case TBM_GETSELSTART
:
1648 return infoPtr
->lSelMin
;
1650 case TBM_GETTHUMBLENGTH
:
1651 return infoPtr
->uThumbLen
;
1653 case TBM_GETTHUMBRECT
:
1654 return CopyRect((LPRECT
)lParam
, &infoPtr
->rcThumb
);
1657 return TRACKBAR_GetTic (infoPtr
, (INT
)wParam
);
1660 return TRACKBAR_GetTicPos (infoPtr
, (INT
)wParam
);
1662 case TBM_GETTOOLTIPS
:
1663 return (LRESULT
)infoPtr
->hwndToolTip
;
1665 case TBM_GETUNICODEFORMAT
:
1666 return infoPtr
->bUnicode
;
1669 return (LRESULT
) TRACKBAR_SetBuddy(infoPtr
, (BOOL
)wParam
, (HWND
)lParam
);
1671 case TBM_SETLINESIZE
:
1672 return TRACKBAR_SetLineSize (infoPtr
, (LONG
)lParam
);
1674 case TBM_SETPAGESIZE
:
1675 return TRACKBAR_SetPageSize (infoPtr
, (LONG
)lParam
);
1678 return TRACKBAR_SetPos (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1681 return TRACKBAR_SetRange (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1683 case TBM_SETRANGEMAX
:
1684 return TRACKBAR_SetRangeMax (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1686 case TBM_SETRANGEMIN
:
1687 return TRACKBAR_SetRangeMin (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1690 return TRACKBAR_SetSel (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1693 return TRACKBAR_SetSelEnd (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1695 case TBM_SETSELSTART
:
1696 return TRACKBAR_SetSelStart (infoPtr
, (BOOL
)wParam
, (LONG
)lParam
);
1698 case TBM_SETTHUMBLENGTH
:
1699 return TRACKBAR_SetThumbLength (infoPtr
, (UINT
)wParam
);
1702 return TRACKBAR_SetTic (infoPtr
, (LONG
)lParam
);
1704 case TBM_SETTICFREQ
:
1705 return TRACKBAR_SetTicFreq (infoPtr
, (WORD
)wParam
);
1707 case TBM_SETTIPSIDE
:
1708 return TRACKBAR_SetTipSide (infoPtr
, (INT
)wParam
);
1710 case TBM_SETTOOLTIPS
:
1711 return TRACKBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
1713 case TBM_SETUNICODEFORMAT
:
1714 return TRACKBAR_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
1717 case WM_CAPTURECHANGED
:
1718 return TRACKBAR_CaptureChanged (infoPtr
);
1721 return TRACKBAR_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1724 return TRACKBAR_Destroy (infoPtr
);
1726 /* case WM_ENABLE: */
1732 return DLGC_WANTARROWS
;
1735 return TRACKBAR_KeyDown (infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
1738 return TRACKBAR_KeyUp (infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
1741 return TRACKBAR_KillFocus (infoPtr
, (HWND
)wParam
);
1743 case WM_LBUTTONDOWN
:
1744 return TRACKBAR_LButtonDown (infoPtr
, wParam
, MAKEPOINTS(lParam
));
1747 return TRACKBAR_LButtonUp (infoPtr
, wParam
, MAKEPOINTS(lParam
));
1750 return TRACKBAR_MouseMove (infoPtr
, wParam
, MAKEPOINTS(lParam
));
1753 return TRACKBAR_Paint (infoPtr
, (HDC
)wParam
);
1756 return TRACKBAR_SetFocus (infoPtr
, (HWND
)wParam
);
1759 return TRACKBAR_Size (infoPtr
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1762 return TRACKBAR_Timer (infoPtr
, (INT
)wParam
, (TIMERPROC
*)lParam
);
1764 case WM_WININICHANGE
:
1765 return TRACKBAR_InitializeThumb (infoPtr
);
1768 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
1769 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
1770 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1776 void TRACKBAR_Register (void)
1780 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1781 wndClass
.style
= CS_GLOBALCLASS
;
1782 wndClass
.lpfnWndProc
= (WNDPROC
)TRACKBAR_WindowProc
;
1783 wndClass
.cbClsExtra
= 0;
1784 wndClass
.cbWndExtra
= sizeof(TRACKBAR_INFO
*);
1785 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1786 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
1787 wndClass
.lpszClassName
= TRACKBAR_CLASSW
;
1789 RegisterClassW (&wndClass
);
1793 void TRACKBAR_Unregister (void)
1795 UnregisterClassW (TRACKBAR_CLASSW
, NULL
);