From 6f395805b18205cd6f9079c9aff35736871d0482 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 2 Sep 2009 16:02:59 +0400 Subject: [PATCH] comctl32/trackbar: Cache window style. --- dlls/comctl32/trackbar.c | 114 ++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/dlls/comctl32/trackbar.c b/dlls/comctl32/trackbar.c index 3e991ff46f..2b9b0644f7 100644 --- a/dlls/comctl32/trackbar.c +++ b/dlls/comctl32/trackbar.c @@ -52,6 +52,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(trackbar); typedef struct { HWND hwndSelf; + DWORD dwStyle; LONG lRangeMin; LONG lRangeMax; LONG lLineSize; @@ -137,7 +138,7 @@ static inline int notify (const TRACKBAR_INFO *infoPtr, INT code) static BOOL notify_with_scroll (const TRACKBAR_INFO *infoPtr, UINT code) { - BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT; + BOOL bVert = infoPtr->dwStyle & TBS_VERT; TRACE("%x\n", code); @@ -213,10 +214,9 @@ TRACKBAR_ConvertPlaceToPosition (const TRACKBAR_INFO *infoPtr, int place, int ve static LONG TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint) { - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); RECT pageRect; - if (dwStyle & TBS_VERT) { + if (infoPtr->dwStyle & TBS_VERT) { pageRect.top = infoPtr->rcChannel.top; pageRect.bottom = infoPtr->rcChannel.bottom; pageRect.left = infoPtr->rcThumb.left; @@ -231,10 +231,10 @@ TRACKBAR_GetAutoPageDirection (const TRACKBAR_INFO *infoPtr, POINT clickPoint) if (PtInRect(&pageRect, clickPoint)) { - int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x; + int clickPlace = (infoPtr->dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x; LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace, - dwStyle & TBS_VERT); + infoPtr->dwStyle & TBS_VERT); return clickPos - infoPtr->lPos; } @@ -285,7 +285,6 @@ static inline void TRACKBAR_LineDown(TRACKBAR_INFO *infoPtr) static void TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr) { - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); INT cyChannel, offsetthumb, offsetedge; RECT lpRect, *channel = & infoPtr->rcChannel; @@ -293,22 +292,22 @@ TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr) offsetthumb = infoPtr->uThumbLen / 4; offsetedge = offsetthumb + 3; - cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4; - if (dwStyle & TBS_VERT) { + cyChannel = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? offsetthumb*3 : 4; + if (infoPtr->dwStyle & TBS_VERT) { channel->top = lpRect.top + offsetedge; channel->bottom = lpRect.bottom - offsetedge; - if (dwStyle & TBS_ENABLESELRANGE) + if (infoPtr->dwStyle & TBS_ENABLESELRANGE) channel->left = lpRect.left + ((infoPtr->uThumbLen - cyChannel + 2) / 2); else channel->left = lpRect.left + (infoPtr->uThumbLen / 2) - 1; - if (dwStyle & TBS_BOTH) { - if (dwStyle & TBS_NOTICKS) + if (infoPtr->dwStyle & TBS_BOTH) { + if (infoPtr->dwStyle & TBS_NOTICKS) channel->left += 1; else channel->left += 9; } - else if (dwStyle & TBS_TOP) { - if (dwStyle & TBS_NOTICKS) + else if (infoPtr->dwStyle & TBS_TOP) { + if (infoPtr->dwStyle & TBS_NOTICKS) channel->left += 2; else channel->left += 10; @@ -317,18 +316,18 @@ TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr) } else { channel->left = lpRect.left + offsetedge; channel->right = lpRect.right - offsetedge; - if (dwStyle & TBS_ENABLESELRANGE) + if (infoPtr->dwStyle & TBS_ENABLESELRANGE) channel->top = lpRect.top + ((infoPtr->uThumbLen - cyChannel + 2) / 2); else channel->top = lpRect.top + (infoPtr->uThumbLen / 2) - 1; - if (dwStyle & TBS_BOTH) { - if (dwStyle & TBS_NOTICKS) + if (infoPtr->dwStyle & TBS_BOTH) { + if (infoPtr->dwStyle & TBS_NOTICKS) channel->top += 1; else channel->top += 9; } - else if (dwStyle & TBS_TOP) { - if (dwStyle & TBS_NOTICKS) + else if (infoPtr->dwStyle & TBS_TOP) { + if (infoPtr->dwStyle & TBS_NOTICKS) channel->top += 2; else channel->top += 10; @@ -341,7 +340,6 @@ static void TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb) { int range, width, height, thumbwidth; - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); RECT lpRect; range = infoPtr->lRangeMax - infoPtr->lRangeMin; @@ -350,11 +348,11 @@ TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb) if (!range) range = 1; GetClientRect(infoPtr->hwndSelf, &lpRect); - if (dwStyle & TBS_VERT) + if (infoPtr->dwStyle & TBS_VERT) { height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - thumbwidth; - if ((dwStyle & (TBS_BOTH | TBS_LEFT)) && !(dwStyle & TBS_NOTICKS)) + if ((infoPtr->dwStyle & (TBS_BOTH | TBS_LEFT)) && !(infoPtr->dwStyle & TBS_NOTICKS)) thumb->left = 10; else thumb->left = 2; @@ -370,7 +368,7 @@ TRACKBAR_CalcThumb (const TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb) thumb->left = infoPtr->rcChannel.left + (width*(lPos - infoPtr->lRangeMin))/range; thumb->right = thumb->left + thumbwidth; - if ((dwStyle & (TBS_BOTH | TBS_TOP)) && !(dwStyle & TBS_NOTICKS)) + if ((infoPtr->dwStyle & (TBS_BOTH | TBS_TOP)) && !(infoPtr->dwStyle & TBS_NOTICKS)) thumb->top = 10; else thumb->top = 2; @@ -424,7 +422,7 @@ TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr) if (range <= 0) { SetRectEmpty (selection); } else { - if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) { + if (infoPtr->dwStyle & TBS_VERT) { offsetthumb = (infoPtr->rcThumb.bottom - infoPtr->rcThumb.top)/2; height = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top - offsetthumb*2; selection->top = infoPtr->rcChannel.top + offsetthumb + @@ -479,7 +477,7 @@ TRACKBAR_DrawChannel (const TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle) if (theme) { DrawThemeBackground (theme, hdc, - (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) ? + (infoPtr->dwStyle & TBS_VERT) ? TKP_TRACKVERT : TKP_TRACK, TKS_NORMAL, &rcChannel, 0); } else @@ -778,7 +776,6 @@ TRACKBAR_ActivateToolTip (const TRACKBAR_INFO *infoPtr, BOOL fShow) static void TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr) { - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); WCHAR buf[80]; static const WCHAR fmt[] = { '%', 'l', 'd', 0 }; TTTOOLINFOW ti; @@ -799,7 +796,7 @@ TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr) GetClientRect (infoPtr->hwndSelf, &rcClient); size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti); - if (dwStyle & TBS_VERT) { + if (infoPtr->dwStyle & TBS_VERT) { if (infoPtr->fLocation == TBTS_LEFT) pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET; else @@ -822,7 +819,6 @@ TRACKBAR_UpdateToolTip (const TRACKBAR_INFO *infoPtr) static void TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst) { - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); RECT rcClient; HDC hdc; HBITMAP hOldBmp = 0, hOffScreenBmp = 0; @@ -889,14 +885,14 @@ TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst) icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT); } else icdrf = CDRF_DODEFAULT; if ( !(icdrf & CDRF_SKIPDEFAULT) ) { - TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle); + TRACKBAR_DrawChannel (infoPtr, hdc, infoPtr->dwStyle); if (icdrf & CDRF_NOTIFYPOSTPAINT) notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT); } /* draw tics */ - if (!(dwStyle & TBS_NOTICKS)) { + if (!(infoPtr->dwStyle & TBS_NOTICKS)) { if (gcdrf & CDRF_NOTIFYITEMDRAW) { nmcd.dwItemSpec = TBCD_TICS; nmcd.uItemState = CDIS_DEFAULT; @@ -904,14 +900,14 @@ TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst) icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT); } else icdrf = CDRF_DODEFAULT; if ( !(icdrf & CDRF_SKIPDEFAULT) ) { - TRACKBAR_DrawTics (infoPtr, hdc, dwStyle); + TRACKBAR_DrawTics (infoPtr, hdc, infoPtr->dwStyle); if (icdrf & CDRF_NOTIFYPOSTPAINT) notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT); } } /* draw thumb */ - if (!(dwStyle & TBS_NOTHUMB)) { + if (!(infoPtr->dwStyle & TBS_NOTHUMB)) { if (gcdrf & CDRF_NOTIFYITEMDRAW) { nmcd.dwItemSpec = TBCD_THUMB; nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT; @@ -919,7 +915,7 @@ TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst) icdrf = notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPREPAINT); } else icdrf = CDRF_DODEFAULT; if ( !(icdrf & CDRF_SKIPDEFAULT) ) { - TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle); + TRACKBAR_DrawThumb(infoPtr, hdc, infoPtr->dwStyle); if (icdrf & CDRF_NOTIFYPOSTPAINT) notify_customdraw(infoPtr, &nmcd, CDDS_ITEMPOSTPAINT); } @@ -948,7 +944,6 @@ cleanup: static void TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr) { - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); HWND hwndParent = GetParent (infoPtr->hwndSelf); RECT rcSelf, rcBuddy; INT x, y; @@ -961,7 +956,7 @@ TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr) GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy); MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2); - if (dwStyle & TBS_VERT) { + if (infoPtr->dwStyle & TBS_VERT) { x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 - (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left; y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top); @@ -982,7 +977,7 @@ TRACKBAR_AlignBuddies (const TRACKBAR_INFO *infoPtr) GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy); MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2); - if (dwStyle & TBS_VERT) { + if (infoPtr->dwStyle & TBS_VERT) { x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 - (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left; y = rcSelf.bottom; @@ -1043,8 +1038,7 @@ TRACKBAR_GetChannelRect (const TRACKBAR_INFO *infoPtr, LPRECT lprc) static inline LONG TRACKBAR_GetNumTics (const TRACKBAR_INFO *infoPtr) { - if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS) - return 0; + if (infoPtr->dwStyle & TBS_NOTICKS) return 0; return infoPtr->uNumTics + 2; } @@ -1223,7 +1217,7 @@ TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin) static inline LRESULT TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel) { - if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){ + if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){ infoPtr->lSelMin = 0; infoPtr->lSelMax = 0; return 0; @@ -1247,7 +1241,7 @@ TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel) static inline LRESULT TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd) { - if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){ + if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){ infoPtr->lSelMax = 0; return 0; } @@ -1267,7 +1261,7 @@ TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd) static inline LRESULT TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart) { - if (!(GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)){ + if (!(infoPtr->dwStyle & TBS_ENABLESELRANGE)){ infoPtr->lSelMin = 0; return 0; } @@ -1287,7 +1281,7 @@ TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart) static inline LRESULT TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength) { - if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH) { + if (infoPtr->dwStyle & TBS_FIXEDLENGTH) { infoPtr->uThumbLen = iLength; infoPtr->flags |= TB_THUMBSIZECHANGED; InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE); @@ -1300,7 +1294,7 @@ TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength) static inline LRESULT TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos) { - if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) + if (infoPtr->dwStyle & TBS_AUTOTICKS) return FALSE; if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax)) @@ -1327,7 +1321,7 @@ TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos) static inline LRESULT TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq) { - if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) { + if (infoPtr->dwStyle & TBS_AUTOTICKS) { infoPtr->uTicFreq = wFreq; TRACKBAR_RecalculateTics (infoPtr); TRACKBAR_InvalidateAll(infoPtr); @@ -1371,14 +1365,13 @@ TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode) static LRESULT TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr) { - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); RECT rect; int clientWidth, clientMetric; /* initial thumb length */ - clientMetric = (dwStyle & TBS_ENABLESELRANGE) ? 23 : 21; + clientMetric = (infoPtr->dwStyle & TBS_ENABLESELRANGE) ? 23 : 21; GetClientRect(infoPtr->hwndSelf,&rect); - if (dwStyle & TBS_VERT) { + if (infoPtr->dwStyle & TBS_VERT) { clientWidth = rect.right - rect.left; } else { clientWidth = rect.bottom - rect.top; @@ -1400,7 +1393,6 @@ static LRESULT TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs) { TRACKBAR_INFO *infoPtr; - DWORD dwStyle; infoPtr = Alloc (sizeof(TRACKBAR_INFO)); if (!infoPtr) return -1; @@ -1408,6 +1400,7 @@ TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs) /* set default values */ infoPtr->hwndSelf = hwnd; + infoPtr->dwStyle = lpcs->style; infoPtr->lRangeMin = 0; infoPtr->lRangeMax = 100; infoPtr->lLineSize = 1; @@ -1423,10 +1416,8 @@ TRACKBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs) TRACKBAR_InitializeThumb (infoPtr); - dwStyle = GetWindowLongW (hwnd, GWL_STYLE); - /* Create tooltip control */ - if (dwStyle & TBS_TOOLTIPS) { + if (infoPtr->dwStyle & TBS_TOOLTIPS) { infoPtr->hwndToolTip = CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP, @@ -1576,6 +1567,16 @@ TRACKBAR_Size (TRACKBAR_INFO *infoPtr) return 0; } +static LRESULT +TRACKBAR_StyleChanged (TRACKBAR_INFO *infoPtr, WPARAM wStyleType, + const STYLESTRUCT *lpss) +{ + if (wStyleType != GWL_STYLE) return 0; + + infoPtr->dwStyle = lpss->styleNew; + + return 0; +} static LRESULT TRACKBAR_Timer (TRACKBAR_INFO *infoPtr) @@ -1603,8 +1604,7 @@ static LRESULT theme_changed (const TRACKBAR_INFO* infoPtr) static LRESULT TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y) { - DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); - INT clickPlace = (dwStyle & TBS_VERT) ? y : x; + INT clickPlace = (infoPtr->dwStyle & TBS_VERT) ? y : x; LONG dragPos, oldPos = infoPtr->lPos; TRACE("(x=%d. y=%d)\n", x, y); @@ -1649,7 +1649,7 @@ TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y) } dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace, - dwStyle & TBS_VERT); + infoPtr->dwStyle & TBS_VERT); if (dragPos == oldPos) return TRUE; infoPtr->lPos = dragPos; @@ -1667,9 +1667,8 @@ TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, INT x, INT y) static BOOL TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey) { - DWORD style = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE); - BOOL downIsLeft = style & TBS_DOWNISLEFT; - BOOL vert = style & TBS_VERT; + BOOL downIsLeft = infoPtr->dwStyle & TBS_DOWNISLEFT; + BOOL vert = infoPtr->dwStyle & TBS_VERT; LONG pos = infoPtr->lPos; TRACE("%x\n", nVirtKey); @@ -1906,6 +1905,9 @@ TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_SIZE: return TRACKBAR_Size (infoPtr); + case WM_STYLECHANGED: + return TRACKBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam); + case WM_THEMECHANGED: return theme_changed (infoPtr); -- 2.32.0.93.g670b81a890