1 /* 2 * Win32 5.1 Theme metrics 3 * 4 * Copyright (C) 2003 Kevin Koltzau 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 #include "uxthemep.h" 22 23 /*********************************************************************** 24 * GetThemeSysBool (UXTHEME.@) 25 */ 26 BOOL WINAPI GetThemeSysBool(HTHEME hTheme, int iBoolID) 27 { 28 HRESULT hr; 29 PTHEME_PROPERTY tp; 30 BOOL ret; 31 PTHEME_CLASS ptc = ValidateHandle(hTheme); 32 33 TRACE("(%p, %d)\n", hTheme, iBoolID); 34 SetLastError(0); 35 if(ptc) { 36 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_BOOL, iBoolID))) { 37 hr = MSSTYLES_GetPropertyBool(tp, &ret); 38 if(SUCCEEDED(hr)) 39 return ret; 40 else 41 SetLastError(hr); 42 } 43 } 44 if(iBoolID == TMT_FLATMENUS) { 45 if(SystemParametersInfoW(SPI_GETFLATMENU, 0, &ret, 0)) 46 return ret; 47 } 48 else { 49 FIXME("Unknown bool id: %d\n", iBoolID); 50 SetLastError(STG_E_INVALIDPARAMETER); 51 } 52 return FALSE; 53 } 54 55 /*********************************************************************** 56 * GetThemeSysColor (UXTHEME.@) 57 */ 58 COLORREF WINAPI GetThemeSysColor(HTHEME hTheme, int iColorID) 59 { 60 HRESULT hr; 61 PTHEME_PROPERTY tp; 62 PTHEME_CLASS ptc = ValidateHandle(hTheme); 63 64 TRACE("(%p, %d)\n", hTheme, iColorID); 65 SetLastError(0); 66 if(ptc) { 67 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_COLOR, iColorID + TMT_FIRSTCOLOR))) { 68 COLORREF color; 69 hr = MSSTYLES_GetPropertyColor(tp, &color); 70 if(SUCCEEDED(hr)) 71 return color; 72 else 73 SetLastError(hr); 74 } 75 } 76 return GetSysColor(iColorID); 77 } 78 79 /*********************************************************************** 80 * GetThemeSysColorBrush (UXTHEME.@) 81 */ 82 HBRUSH WINAPI GetThemeSysColorBrush(HTHEME hTheme, int iColorID) 83 { 84 TRACE("(%p, %d)\n", hTheme, iColorID); 85 return CreateSolidBrush(GetThemeSysColor(hTheme, iColorID)); 86 } 87 88 /*********************************************************************** 89 * GetThemeSysFont (UXTHEME.@) 90 */ 91 HRESULT WINAPI GetThemeSysFont(HTHEME hTheme, int iFontID, LOGFONTW *plf) 92 { 93 HRESULT hr = S_OK; 94 PTHEME_PROPERTY tp; 95 PTHEME_CLASS ptc = ValidateHandle(hTheme); 96 97 TRACE("(%p, %d)\n", hTheme, iFontID); 98 if(ptc) { 99 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_FONT, iFontID))) { 100 HDC hdc = GetDC(NULL); 101 hr = MSSTYLES_GetPropertyFont(tp, hdc, plf); 102 ReleaseDC(NULL, hdc); 103 if(SUCCEEDED(hr)) 104 return S_OK; 105 } 106 } 107 if(iFontID == TMT_ICONTITLEFONT) { 108 if(!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(LOGFONTW), plf, 0)) 109 return HRESULT_FROM_WIN32(GetLastError()); 110 } 111 else { 112 NONCLIENTMETRICSW ncm; 113 LOGFONTW *font = NULL; 114 ncm.cbSize = sizeof(NONCLIENTMETRICSW); 115 if(!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0)) 116 return HRESULT_FROM_WIN32(GetLastError()); 117 switch(iFontID) { 118 case TMT_CAPTIONFONT: font = &ncm.lfCaptionFont; break; 119 case TMT_SMALLCAPTIONFONT: font = &ncm.lfSmCaptionFont; break; 120 case TMT_MENUFONT: font = &ncm.lfMenuFont; break; 121 case TMT_STATUSFONT: font = &ncm.lfStatusFont; break; 122 case TMT_MSGBOXFONT: font = &ncm.lfMessageFont; break; 123 default: FIXME("Unknown FontID: %d\n", iFontID); break; 124 } 125 if(font) *plf = *font; 126 else hr = STG_E_INVALIDPARAMETER; 127 } 128 return hr; 129 } 130 131 /*********************************************************************** 132 * GetThemeSysInt (UXTHEME.@) 133 */ 134 HRESULT WINAPI GetThemeSysInt(HTHEME hTheme, int iIntID, int *piValue) 135 { 136 PTHEME_PROPERTY tp; 137 PTHEME_CLASS ptc = ValidateHandle(hTheme); 138 139 TRACE("(%p, %d)\n", hTheme, iIntID); 140 if(!ptc) 141 return E_HANDLE; 142 if(iIntID < TMT_FIRSTINT || iIntID > TMT_LASTINT) { 143 WARN("Unknown IntID: %d\n", iIntID); 144 return STG_E_INVALIDPARAMETER; 145 } 146 if((tp = MSSTYLES_FindMetric(ptc->tf , TMT_INT, iIntID))) 147 return MSSTYLES_GetPropertyInt(tp, piValue); 148 return E_PROP_ID_UNSUPPORTED; 149 } 150 151 /*********************************************************************** 152 * GetThemeSysSize (UXTHEME.@) 153 */ 154 int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID) 155 { 156 PTHEME_PROPERTY tp; 157 int i, id = -1; 158 int metricMap[] = { 159 SM_CXVSCROLL, TMT_SCROLLBARWIDTH, 160 SM_CYHSCROLL, TMT_SCROLLBARHEIGHT, 161 SM_CXSIZE, TMT_CAPTIONBARWIDTH, 162 SM_CYSIZE, TMT_CAPTIONBARHEIGHT, 163 SM_CXFRAME, TMT_SIZINGBORDERWIDTH, 164 SM_CYFRAME, TMT_SIZINGBORDERWIDTH, /* There is no TMT_SIZINGBORDERHEIGHT, but this works in windows.. */ 165 SM_CXSMSIZE, TMT_SMCAPTIONBARWIDTH, 166 SM_CYSMSIZE, TMT_SMCAPTIONBARHEIGHT, 167 SM_CXMENUSIZE, TMT_MENUBARWIDTH, 168 SM_CYMENUSIZE, TMT_MENUBARHEIGHT 169 }; 170 PTHEME_CLASS ptc = ValidateHandle(hTheme); 171 172 if(ptc) { 173 for(i=0; i<sizeof(metricMap)/sizeof(metricMap[0]); i+=2) { 174 if(metricMap[i] == iSizeID) { 175 id = metricMap[i+1]; 176 break; 177 } 178 } 179 SetLastError(0); 180 if(id != -1) { 181 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_SIZE, id))) { 182 if(SUCCEEDED(MSSTYLES_GetPropertyInt(tp, &i))) { 183 return i; 184 } 185 } 186 TRACE("Size %d not found in theme, using system metric\n", iSizeID); 187 } 188 else { 189 SetLastError(STG_E_INVALIDPARAMETER); 190 return 0; 191 } 192 } 193 194 195 // TODO: Check if this is correct 196 // In windows for SM_CXFRAME this function returns what seems to be the non client metric iBorderWidth 197 if (iSizeID == SM_CXFRAME) 198 return GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME); 199 return GetSystemMetrics(iSizeID); 200 } 201 202 /*********************************************************************** 203 * GetThemeSysString (UXTHEME.@) 204 */ 205 HRESULT WINAPI GetThemeSysString(HTHEME hTheme, int iStringID, 206 LPWSTR pszStringBuff, int cchMaxStringChars) 207 { 208 PTHEME_PROPERTY tp; 209 PTHEME_CLASS ptc = ValidateHandle(hTheme); 210 211 TRACE("(%p, %d)\n", hTheme, iStringID); 212 if(!ptc) 213 return E_HANDLE; 214 if(iStringID < TMT_FIRSTSTRING || iStringID > TMT_LASTSTRING) { 215 WARN("Unknown StringID: %d\n", iStringID); 216 return STG_E_INVALIDPARAMETER; 217 } 218 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_STRING, iStringID))) 219 return MSSTYLES_GetPropertyString(tp, pszStringBuff, cchMaxStringChars); 220 return E_PROP_ID_UNSUPPORTED; 221 } 222 223 #ifndef __REACTOS__ 224 /*********************************************************************** 225 * GetThemeTransitionDuration (UXTHEME.@) 226 */ 227 HRESULT WINAPI GetThemeTransitionDuration(HTHEME hTheme, int iPartId, int iStateIdFrom, 228 int iStateIdTo, int iPropId, DWORD *pdwDuration) 229 { 230 FIXME("(%p, %u, %u, %u, %u, %p) stub\n", hTheme, iPartId, iStateIdFrom, iStateIdTo, 231 iPropId, pdwDuration); 232 233 return E_NOTIMPL; 234 } 235 #endif 236