uxtheme: Use the ARRAY_SIZE() macro.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Stefaniuc 2018-09-18 20:38:19 +02:00 committed by Alexandre Julliard
parent bfad5527ac
commit 93994dfc0b
6 changed files with 38 additions and 43 deletions

View file

@ -198,8 +198,7 @@ static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId,
HBITMAP hBmp; HBITMAP hBmp;
BOOL hasAlpha; BOOL hasAlpha;
lstrcpynW(szPath, fileProp->lpValue, lstrcpynW(szPath, fileProp->lpValue, min(fileProp->dwValueLen+1, ARRAY_SIZE(szPath)));
min(fileProp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, &hasAlpha); hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, &hasAlpha);
if(!hBmp) continue; if(!hBmp) continue;
@ -245,7 +244,7 @@ static HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iState
FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId, iStateId); FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId, iStateId);
return E_PROP_ID_UNSUPPORTED; return E_PROP_ID_UNSUPPORTED;
} }
lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0]))); lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, ARRAY_SIZE(szPath)));
*hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, hasImageAlpha); *hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, hasImageAlpha);
if(!*hBmp) { if(!*hBmp) {
TRACE("Failed to load bitmap %s\n", debugstr_w(szPath)); TRACE("Failed to load bitmap %s\n", debugstr_w(szPath));

View file

@ -181,7 +181,7 @@ int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID)
}; };
if(hTheme) { if(hTheme) {
for(i=0; i<sizeof(metricMap)/sizeof(metricMap[0]); i+=2) { for(i=0; i<ARRAY_SIZE(metricMap); i+=2) {
if(metricMap[i] == iSizeID) { if(metricMap[i] == iSizeID) {
id = metricMap[i+1]; id = metricMap[i+1];
break; break;

View file

@ -344,7 +344,7 @@ static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR
WCHAR state[60] = {'\0'}; WCHAR state[60] = {'\0'};
LPWSTR tmp; LPWSTR tmp;
LPWSTR comp; LPWSTR comp;
lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0]))); lstrcpynW(sec, lpSection, min(dwLen+1, ARRAY_SIZE(sec)));
*szAppName = 0; *szAppName = 0;
*szClassName = 0; *szClassName = 0;
@ -369,17 +369,17 @@ static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR
tmp = strchrW(comp, '('); tmp = strchrW(comp, '(');
if(tmp) { if(tmp) {
*tmp++ = 0; *tmp++ = 0;
lstrcpynW(part, comp, sizeof(part)/sizeof(part[0])); lstrcpynW(part, comp, ARRAY_SIZE(part));
comp = tmp; comp = tmp;
/* now get the state */ /* now get the state */
tmp = strchrW(comp, ')'); tmp = strchrW(comp, ')');
if (!tmp) if (!tmp)
return FALSE; return FALSE;
*tmp = 0; *tmp = 0;
lstrcpynW(state, comp, sizeof(state)/sizeof(state[0])); lstrcpynW(state, comp, ARRAY_SIZE(state));
} }
else { else {
lstrcpynW(part, comp, sizeof(part)/sizeof(part[0])); lstrcpynW(part, comp, ARRAY_SIZE(part));
} }
} }
else { else {
@ -393,7 +393,7 @@ static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR
if (!tmp) if (!tmp)
return FALSE; return FALSE;
*tmp = 0; *tmp = 0;
lstrcpynW(state, comp, sizeof(state)/sizeof(state[0])); lstrcpynW(state, comp, ARRAY_SIZE(state));
} }
else { else {
lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME); lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
@ -897,7 +897,7 @@ static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
parse_init_nonclient (&nonClientState); parse_init_nonclient (&nonClientState);
while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) { while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0]))); lstrcpynW(szPropertyName, lpName, min(dwLen+1, ARRAY_SIZE(szPropertyName)));
if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) { if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) { if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
if (!parse_handle_color_property (&colorState, iPropertyId, if (!parse_handle_color_property (&colorState, iPropertyId,
@ -948,7 +948,7 @@ static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
ps = MSSTYLES_AddPartState(cls, iPartId, iStateId); ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) { while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0]))); lstrcpynW(szPropertyName, lpName, min(dwLen+1, ARRAY_SIZE(szPropertyName)));
if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) { if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal); MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
} }
@ -1014,13 +1014,13 @@ PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList)
start = pszClassList; start = pszClassList;
while((end = strchrW(start, ';'))) { while((end = strchrW(start, ';'))) {
len = end-start; len = end-start;
lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0]))); lstrcpynW(szClassName, start, min(len+1, ARRAY_SIZE(szClassName)));
start = end+1; start = end+1;
cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName); cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
if(cls) break; if(cls) break;
} }
if(!cls && *start) { if(!cls && *start) {
lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0])); lstrcpynW(szClassName, start, ARRAY_SIZE(szClassName));
cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName); cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
} }
if(cls) { if(cls) {
@ -1120,7 +1120,7 @@ HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha
WCHAR szFile[MAX_PATH]; WCHAR szFile[MAX_PATH];
LPWSTR tmp; LPWSTR tmp;
PTHEME_IMAGE img; PTHEME_IMAGE img;
lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0])); lstrcpynW(szFile, lpFilename, ARRAY_SIZE(szFile));
tmp = szFile; tmp = szFile;
do { do {
if(*tmp == '\\') *tmp = '_'; if(*tmp == '\\') *tmp = '_';
@ -1273,7 +1273,7 @@ static HRESULT MSSTYLES_GetFont (LPCWSTR lpCur, LPCWSTR lpEnd,
pFont->lfHeight = pointSize; pFont->lfHeight = pointSize;
pFont->lfWeight = FW_REGULAR; pFont->lfWeight = FW_REGULAR;
pFont->lfCharSet = DEFAULT_CHARSET; pFont->lfCharSet = DEFAULT_CHARSET;
while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, sizeof(attr)/sizeof(attr[0]))) { while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, ARRAY_SIZE(attr))) {
if(!lstrcmpiW(szBold, attr)) pFont->lfWeight = FW_BOLD; if(!lstrcmpiW(szBold, attr)) pFont->lfWeight = FW_BOLD;
else if(!lstrcmpiW(szItalic, attr)) pFont->lfItalic = TRUE; else if(!lstrcmpiW(szItalic, attr)) pFont->lfItalic = TRUE;
else if(!lstrcmpiW(szUnderline, attr)) pFont->lfUnderline = TRUE; else if(!lstrcmpiW(szUnderline, attr)) pFont->lfUnderline = TRUE;

View file

@ -87,7 +87,7 @@ HRESULT WINAPI GetThemeEnumValue(HTHEME hTheme, int iPartId, int iStateId,
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_ENUM, iPropId))) if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_ENUM, iPropId)))
return E_PROP_ID_UNSUPPORTED; return E_PROP_ID_UNSUPPORTED;
hr = MSSTYLES_GetPropertyString(tp, val, sizeof(val)/sizeof(val[0])); hr = MSSTYLES_GetPropertyString(tp, val, ARRAY_SIZE(val));
if(FAILED(hr)) if(FAILED(hr))
return hr; return hr;
if(!MSSTYLES_LookupEnum(val, iPropId, piVal)) if(!MSSTYLES_LookupEnum(val, iPropId, piVal))
@ -262,7 +262,7 @@ HRESULT WINAPI GetThemeMetric(HTHEME hTheme, HDC hdc, int iPartId,
case TMT_COLOR: case TMT_COLOR:
return MSSTYLES_GetPropertyColor(tp, (COLORREF*)piVal); return MSSTYLES_GetPropertyColor(tp, (COLORREF*)piVal);
case TMT_ENUM: case TMT_ENUM:
hr = MSSTYLES_GetPropertyString(tp, val, sizeof(val)/sizeof(val[0])); hr = MSSTYLES_GetPropertyString(tp, val, ARRAY_SIZE(val));
if(FAILED(hr)) if(FAILED(hr))
return hr; return hr;
if(!MSSTYLES_LookupEnum(val, iPropId, piVal)) if(!MSSTYLES_LookupEnum(val, iPropId, piVal))

View file

@ -1051,7 +1051,7 @@ BOOL MSSTYLES_LookupPartState(LPCWSTR pszClass, LPCWSTR pszPart, LPCWSTR pszStat
*iPartId = 0; *iPartId = 0;
*iStateId = 0; *iStateId = 0;
for(i=0; i<sizeof(mapClass)/sizeof(mapClass[0]); i++) { for(i=0; i<ARRAY_SIZE(mapClass); i++) {
if(!lstrcmpiW(mapClass[i].pszClass, pszClass)) { if(!lstrcmpiW(mapClass[i].pszClass, pszClass)) {
map = mapClass[i].lpMap; map = mapClass[i].lpMap;
if(pszPart) { if(pszPart) {

View file

@ -159,7 +159,7 @@ static void UXTHEME_LoadTheme(void)
/* Get current theme configuration */ /* Get current theme configuration */
if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) { if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
TRACE("Loading theme config\n"); TRACE("Loading theme config\n");
buffsize = sizeof(tmp)/sizeof(tmp[0]); buffsize = ARRAY_SIZE(tmp);
if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) { if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) {
bThemeActive = (tmp[0] != '0'); bThemeActive = (tmp[0] != '0');
} }
@ -167,10 +167,10 @@ static void UXTHEME_LoadTheme(void)
bThemeActive = FALSE; bThemeActive = FALSE;
TRACE("Failed to get ThemeActive: %d\n", GetLastError()); TRACE("Failed to get ThemeActive: %d\n", GetLastError());
} }
buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]); buffsize = ARRAY_SIZE(szCurrentColor);
if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize)) if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize))
szCurrentColor[0] = '\0'; szCurrentColor[0] = '\0';
buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]); buffsize = ARRAY_SIZE(szCurrentSize);
if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize)) if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize))
szCurrentSize[0] = '\0'; szCurrentSize[0] = '\0';
if (query_reg_path (hKey, szDllName, szCurrentTheme)) if (query_reg_path (hKey, szDllName, szCurrentTheme))
@ -194,8 +194,8 @@ static void UXTHEME_LoadTheme(void)
} }
else { else {
/* Make sure the global color & size match the theme */ /* Make sure the global color & size match the theme */
lstrcpynW(szCurrentColor, pt->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0])); lstrcpynW(szCurrentColor, pt->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
lstrcpynW(szCurrentSize, pt->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0])); lstrcpynW(szCurrentSize, pt->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
MSSTYLES_SetActiveTheme(pt, FALSE); MSSTYLES_SetActiveTheme(pt, FALSE);
TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme), TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
@ -477,9 +477,9 @@ static HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
return hr; return hr;
if(tf) { if(tf) {
bThemeActive = TRUE; bThemeActive = TRUE;
lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0])); lstrcpynW(szCurrentTheme, tf->szThemeFile, ARRAY_SIZE(szCurrentTheme));
lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0])); lstrcpynW(szCurrentColor, tf->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0])); lstrcpynW(szCurrentSize, tf->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
} }
else { else {
UXTHEME_RestoreSystemMetrics(); UXTHEME_RestoreSystemMetrics();
@ -661,9 +661,9 @@ HTHEME WINAPI OpenThemeDataEx(HWND hwnd, LPCWSTR pszClassList, DWORD flags)
if(bThemeActive) if(bThemeActive)
{ {
pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0])); pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, ARRAY_SIZE(szAppBuff));
/* If SetWindowTheme was used on the window, that overrides the class list passed to this function */ /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0])); pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, ARRAY_SIZE(szClassBuff));
if(!pszUseClassList) if(!pszUseClassList)
pszUseClassList = pszClassList; pszUseClassList = pszClassList;
@ -837,7 +837,7 @@ HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
/* Try to load from string resources */ /* Try to load from string resources */
hr = E_PROP_ID_UNSUPPORTED; hr = E_PROP_ID_UNSUPPORTED;
if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) { if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) { for(i=0; i<ARRAY_SIZE(wDocToRes); i+=2) {
if(wDocToRes[i] == iDocId) { if(wDocToRes[i] == iDocId) {
if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) { if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
hr = S_OK; hr = S_OK;
@ -1049,9 +1049,9 @@ HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
&& !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) { && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName); wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0])); hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, ARRAY_SIZE(szName));
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0])); hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, ARRAY_SIZE(szTip));
if(SUCCEEDED(hr)) { if(SUCCEEDED(hr)) {
TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData); TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) { if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
@ -1113,12 +1113,10 @@ HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
if(!dwColorNum && *tmp) { if(!dwColorNum && *tmp) {
TRACE("%s\n", debugstr_w(tmp)); TRACE("%s\n", debugstr_w(tmp));
lstrcpyW(pszColorNames->szName, tmp); lstrcpyW(pszColorNames->szName, tmp);
LoadStringW (pt->hTheme, resourceId, LoadStringW(pt->hTheme, resourceId, pszColorNames->szDisplayName,
pszColorNames->szDisplayName, ARRAY_SIZE(pszColorNames->szDisplayName));
sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR)); LoadStringW(pt->hTheme, resourceId+1000, pszColorNames->szTooltip,
LoadStringW (pt->hTheme, resourceId+1000, ARRAY_SIZE(pszColorNames->szTooltip));
pszColorNames->szTooltip,
sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
} }
else else
hr = E_PROP_ID_UNSUPPORTED; hr = E_PROP_ID_UNSUPPORTED;
@ -1173,12 +1171,10 @@ HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
if(!dwSizeNum && *tmp) { if(!dwSizeNum && *tmp) {
TRACE("%s\n", debugstr_w(tmp)); TRACE("%s\n", debugstr_w(tmp));
lstrcpyW(pszSizeNames->szName, tmp); lstrcpyW(pszSizeNames->szName, tmp);
LoadStringW (pt->hTheme, resourceId, LoadStringW(pt->hTheme, resourceId, pszSizeNames->szDisplayName,
pszSizeNames->szDisplayName, ARRAY_SIZE(pszSizeNames->szDisplayName));
sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR)); LoadStringW(pt->hTheme, resourceId+1000, pszSizeNames->szTooltip,
LoadStringW (pt->hTheme, resourceId+1000, ARRAY_SIZE(pszSizeNames->szTooltip));
pszSizeNames->szTooltip,
sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
} }
else else
hr = E_PROP_ID_UNSUPPORTED; hr = E_PROP_ID_UNSUPPORTED;