The initial size of the thumb depends on SM_CYCAPTION.

Correctly draw the thumb as in Windows.
The channel/thumb position also depends on TBS_NOTICKS.
The first and last tic marks should be inset from the channel length
by half the thumb width.
When TBS_BOTH style set, make sure to draw both sets of tics.
This commit is contained in:
Duane Clark 2003-08-02 00:44:00 +00:00 committed by Alexandre Julliard
parent aeffb6c312
commit 9ebf12c36d
1 changed files with 80 additions and 59 deletions

View File

@ -139,15 +139,17 @@ static inline LONG
TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO *infoPtr, int place, TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO *infoPtr, int place,
int vertical) int vertical)
{ {
double range, width, pos; double range, width, pos, offsetthumb;
range = infoPtr->lRangeMax - infoPtr->lRangeMin; range = infoPtr->lRangeMax - infoPtr->lRangeMin;
if (vertical) { if (vertical) {
width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top; offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2 + 1;
pos = (range*(place - infoPtr->rcChannel.top)) / width; width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - (offsetthumb * 2);
pos = (range*(place - infoPtr->rcChannel.top - offsetthumb)) / width;
} else { } else {
width = infoPtr->rcChannel.right - infoPtr->rcChannel.left; offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2 + 1;
pos = (range*(place - infoPtr->rcChannel.left)) / width; width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - (offsetthumb * 2);
pos = (range*(place - infoPtr->rcChannel.left - offsetthumb)) / width;
} }
pos += infoPtr->lRangeMin; pos += infoPtr->lRangeMin;
if (pos > infoPtr->lRangeMax) if (pos > infoPtr->lRangeMax)
@ -224,22 +226,42 @@ TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
GetClientRect (infoPtr->hwndSelf, &lpRect); GetClientRect (infoPtr->hwndSelf, &lpRect);
offsetthumb = (int)(infoPtr->uThumbLen/4.5); offsetthumb = infoPtr->uThumbLen / 4;
offsetedge = offsetthumb + 3; offsetedge = offsetthumb + 3;
cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? (offsetthumb+1)*3 : 4; cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? (offsetthumb+1)*3 : 4;
if (dwStyle & TBS_VERT) { if (dwStyle & TBS_VERT) {
channel->top = lpRect.top + offsetedge; channel->top = lpRect.top + offsetedge;
channel->bottom = lpRect.bottom - offsetedge; channel->bottom = lpRect.bottom - offsetedge;
channel->left = lpRect.left + offsetthumb - cyChannel; channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1;
if (dwStyle & (TBS_BOTH | TBS_LEFT)) if (dwStyle & TBS_BOTH) {
channel->left += (lpRect.right-lpRect.left-offsetthumb-cyChannel)/2; if (dwStyle & TBS_NOTICKS)
channel->left += 1;
else
channel->left += 9;
}
else if (dwStyle & TBS_TOP) {
if (dwStyle & TBS_NOTICKS)
channel->left += 2;
else
channel->left += 10;
}
channel->right = channel->left + cyChannel; channel->right = channel->left + cyChannel;
} else { } else {
channel->left = lpRect.left + offsetedge; channel->left = lpRect.left + offsetedge;
channel->right = lpRect.right - offsetedge; channel->right = lpRect.right - offsetedge;
channel->top = lpRect.top + offsetedge; channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1;
if (dwStyle & (TBS_BOTH | TBS_TOP)) if (dwStyle & TBS_BOTH) {
channel->top += (lpRect.bottom-lpRect.top-offsetedge-cyChannel)/2; if (dwStyle & TBS_NOTICKS)
channel->top += 1;
else
channel->top += 9;
}
else if (dwStyle & TBS_TOP) {
if (dwStyle & TBS_NOTICKS)
channel->top += 2;
else
channel->top += 10;
}
channel->bottom = channel->top + cyChannel; channel->bottom = channel->top + cyChannel;
} }
} }
@ -247,43 +269,41 @@ TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
static void static void
TRACKBAR_CalcThumb (TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb) TRACKBAR_CalcThumb (TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
{ {
int range, width, height, thumbdepth, ticOffset = 5 + 2; /* 5 is length of tic, 2 is extra indent */ int range, width, height, thumbwidth;
DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
RECT lpRect; RECT lpRect;
range = infoPtr->lRangeMax - infoPtr->lRangeMin; range = infoPtr->lRangeMax - infoPtr->lRangeMin;
thumbdepth = ((int)(infoPtr->uThumbLen / 4.5)) + 2; thumbwidth = (infoPtr->uThumbLen / 2) | 1;
if (!range) range = 1; if (!range) range = 1;
GetClientRect(infoPtr->hwndSelf, &lpRect); GetClientRect(infoPtr->hwndSelf, &lpRect);
if (dwStyle & TBS_VERT) if (dwStyle & TBS_VERT)
{ {
height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top; height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth - 1;
if (dwStyle & (TBS_BOTH | TBS_LEFT)) if ((dwStyle & (TBS_BOTH | TBS_LEFT)) && !(dwStyle & TBS_NOTICKS))
thumb->left = (lpRect.right - lpRect.left - infoPtr->uThumbLen)/2 + ticOffset; thumb->left = 10;
else else
thumb->left = 2; thumb->left = 2;
thumb->right = thumb->left + infoPtr->uThumbLen - (ticOffset * 2); thumb->right = thumb->left + infoPtr->uThumbLen;
thumb->top = infoPtr->rcChannel.top + thumb->top = infoPtr->rcChannel.top +
(height*(lPos - infoPtr->lRangeMin))/range - (height*(lPos - infoPtr->lRangeMin))/range;
thumbdepth/2; thumb->bottom = thumb->top + thumbwidth;
thumb->bottom = thumb->top + thumbdepth;
} }
else else
{ {
width = infoPtr->rcChannel.right - infoPtr->rcChannel.left; width = infoPtr->rcChannel.right - infoPtr->rcChannel.left - thumbwidth - 1;
thumb->left = infoPtr->rcChannel.left + thumb->left = infoPtr->rcChannel.left +
(width*(lPos - infoPtr->lRangeMin))/range - (width*(lPos - infoPtr->lRangeMin))/range;
thumbdepth/2; thumb->right = thumb->left + thumbwidth;
thumb->right = thumb->left + thumbdepth; if ((dwStyle & (TBS_BOTH | TBS_TOP)) && !(dwStyle & TBS_NOTICKS))
if (dwStyle & (TBS_BOTH | TBS_TOP)) thumb->top = 10;
thumb->top = (lpRect.bottom - lpRect.top - infoPtr->uThumbLen)/2;
else else
thumb->top = 2; thumb->top = 2;
thumb->bottom = thumb->top + infoPtr->uThumbLen - 20; /* double the bottom padding for the ticks, chosen to resemble native control */ thumb->bottom = thumb->top + infoPtr->uThumbLen;
} }
} }
@ -381,16 +401,6 @@ static void
TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle) TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
{ {
RECT rcChannel = infoPtr->rcChannel; RECT rcChannel = infoPtr->rcChannel;
int runOver = 5;
/* make the channel slightly overrun the last tick, to make it look more like the native control, and less "clunky" */
if (dwStyle & TBS_VERT) {
rcChannel.top -= runOver;
rcChannel.bottom += runOver;
} else {
rcChannel.left -= runOver;
rcChannel.right += runOver;
}
DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST); DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */ if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
@ -403,19 +413,22 @@ TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
static void static void
TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags) TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
{ {
int x, y, ox, oy, range, side, offset = 5, indent = 0, len = 3; int x, y, ox, oy, range, side, indent = 0, len = 3;
int offsetthumb;
RECT rcTics; RECT rcTics;
TRACE("\n");
GetClientRect(infoPtr->hwndSelf, &rcTics);
if (flags & TBS_VERT) { if (flags & TBS_VERT) {
rcTics.top = infoPtr->rcChannel.top; offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2 + 1;
rcTics.bottom = infoPtr->rcChannel.bottom; rcTics.left = infoPtr->rcThumb.left - 2;
rcTics.right = infoPtr->rcThumb.right + 2;
rcTics.top = infoPtr->rcChannel.top + offsetthumb;
rcTics.bottom = infoPtr->rcChannel.bottom - offsetthumb;
} else { } else {
rcTics.left = infoPtr->rcChannel.left; offsetthumb = (infoPtr->rcThumb.right - infoPtr->rcThumb.left)/2 + 1;
rcTics.right = infoPtr->rcChannel.right; rcTics.left = infoPtr->rcChannel.left + offsetthumb;
rcTics.bottom -= 10; /* value obtained by guesswork and experimentation */ rcTics.right = infoPtr->rcChannel.right - offsetthumb;
rcTics.top = infoPtr->rcThumb.top - 2;
rcTics.bottom = infoPtr->rcThumb.bottom + 2;
} }
if (flags & (TBS_TOP | TBS_LEFT)) { if (flags & (TBS_TOP | TBS_LEFT)) {
@ -441,13 +454,13 @@ TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
if (flags & TBS_VERT) { if (flags & TBS_VERT) {
int height = rcTics.bottom - rcTics.top; int height = rcTics.bottom - rcTics.top;
y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range; y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
x -= (offset + 2) * side; /* x -= (offset + 2) * side;
y += indent; y += indent;*/
} else { } else {
int width = rcTics.right - rcTics.left; int width = rcTics.right - rcTics.left;
x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range; x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
x += indent; /* x += indent;
y -= (offset + 2) * side; y -= (offset + 2) * side;*/
} }
ox = x; ox = x;
@ -483,7 +496,7 @@ TRACKBAR_DrawTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT); TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH)) if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags); TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags & ~TBS_LEFT);
} }
static void static void
@ -528,8 +541,8 @@ TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
int PointCount = 6; int PointCount = 6;
POINT points[6]; POINT points[6];
int fillClr; int fillClr;
int PointDepth;
static INT PointDepth = 4;
fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE; fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
oldbr = SelectObject (hdc, GetSysColorBrush(fillClr)); oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
SetPolyFillMode (hdc, WINDING); SetPolyFillMode (hdc, WINDING);
@ -553,6 +566,7 @@ TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
{ {
if (dwStyle & TBS_VERT) if (dwStyle & TBS_VERT)
{ {
PointDepth = (thumb.bottom - thumb.top) / 2;
if (dwStyle & TBS_LEFT) if (dwStyle & TBS_LEFT)
{ {
points[0].x=thumb.right; points[0].x=thumb.right;
@ -562,7 +576,7 @@ TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
points[2].x=thumb.left + PointDepth; points[2].x=thumb.left + PointDepth;
points[2].y=thumb.bottom; points[2].y=thumb.bottom;
points[3].x=thumb.left; points[3].x=thumb.left;
points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top; points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
points[4].x=thumb.left + PointDepth; points[4].x=thumb.left + PointDepth;
points[4].y=thumb.top; points[4].y=thumb.top;
points[5].x=points[0].x; points[5].x=points[0].x;
@ -572,7 +586,7 @@ TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
else else
{ {
points[0].x=thumb.right; points[0].x=thumb.right;
points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top; points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top + 1;
points[1].x=thumb.right - PointDepth; points[1].x=thumb.right - PointDepth;
points[1].y=thumb.bottom; points[1].y=thumb.bottom;
points[2].x=thumb.left; points[2].x=thumb.left;
@ -587,9 +601,10 @@ TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
} }
else else
{ {
PointDepth = (thumb.right - thumb.left) / 2;
if (dwStyle & TBS_TOP) if (dwStyle & TBS_TOP)
{ {
points[0].x=(thumb.right - thumb.left) / 2 + thumb.left ; points[0].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
points[0].y=thumb.top; points[0].y=thumb.top;
points[1].x=thumb.right; points[1].x=thumb.right;
points[1].y=thumb.top + PointDepth; points[1].y=thumb.top + PointDepth;
@ -609,7 +624,7 @@ TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
points[0].y=thumb.top; points[0].y=thumb.top;
points[1].x=thumb.right; points[1].x=thumb.right;
points[1].y=thumb.bottom - PointDepth; points[1].y=thumb.bottom - PointDepth;
points[2].x=(thumb.right - thumb.left) / 2 + thumb.left ; points[2].x=(thumb.right - thumb.left) / 2 + thumb.left + 1;
points[2].y=thumb.bottom; points[2].y=thumb.bottom;
points[3].x=thumb.left; points[3].x=thumb.left;
points[3].y=thumb.bottom - PointDepth; points[3].y=thumb.bottom - PointDepth;
@ -1228,14 +1243,20 @@ TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
{ {
DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
RECT rect; RECT rect;
int clientWidth, clientMetric;
/* initial thumb length */ /* initial thumb length */
clientMetric = GetSystemMetrics(SM_CYCAPTION);
GetClientRect(infoPtr->hwndSelf,&rect); GetClientRect(infoPtr->hwndSelf,&rect);
if (dwStyle & TBS_VERT) { if (dwStyle & TBS_VERT) {
infoPtr->uThumbLen = (rect.right - rect.left - 6); clientWidth = rect.right - rect.left;
} else { } else {
infoPtr->uThumbLen = (rect.bottom - rect.top); clientWidth = rect.bottom - rect.top;
} }
if (clientWidth > clientMetric)
infoPtr->uThumbLen = clientMetric + 1;
else
infoPtr->uThumbLen = clientWidth > 9 ? clientWidth - 6 : 4;
TRACKBAR_CalcChannel (infoPtr); TRACKBAR_CalcChannel (infoPtr);
TRACKBAR_UpdateThumb (infoPtr); TRACKBAR_UpdateThumb (infoPtr);