license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | // |
| 5 | // A wrapper class for working with custom XP/Vista themes provided in |
| 6 | // uxtheme.dll. This is a singleton class that can be grabbed using |
| 7 | // NativeTheme::instance(). |
| 8 | // For more information on visual style parts and states, see: |
| 9 | // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/topics/partsandstates.asp |
| 10 | |
| 11 | #ifndef BASE_GFX_NATIVE_THEME_H__ |
| 12 | #define BASE_GFX_NATIVE_THEME_H__ |
| 13 | |
| 14 | #include <windows.h> |
| 15 | #include <uxtheme.h> |
| 16 | #include "base/basictypes.h" |
| 17 | #include "base/gfx/size.h" |
| 18 | #include "skia/include/SkColor.h" |
| 19 | |
| 20 | namespace gfx { |
awalker@google.com | bce88e1 | 2008-08-15 02:47:00 +0900 | [diff] [blame] | 21 | class PlatformCanvasWin; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 22 | |
| 23 | // TODO: Define class member enums to replace part_id and state_id parameters |
| 24 | // that are currently defined in <vssym32.h>. Afterward, classic_state should |
| 25 | // be removed and class users wouldn't need to include <vssym32.h> anymore. |
| 26 | // This would enable HOT state on non-themed UI (like when RDP'ing) and would |
| 27 | // simplify usage. |
| 28 | // TODO: This class should probably be changed to be platform independent at |
| 29 | // the same time. |
| 30 | class NativeTheme { |
| 31 | public: |
| 32 | enum ThemeName { |
| 33 | BUTTON, |
| 34 | TEXTFIELD, |
| 35 | MENULIST, |
| 36 | SCROLLBAR, |
| 37 | STATUS, |
| 38 | MENU, |
| 39 | WINDOW, |
| 40 | TAB, |
| 41 | LIST, |
| 42 | LAST |
| 43 | }; |
| 44 | |
| 45 | // This enumeration is used within PaintMenuArrow in order to indicate the |
| 46 | // direction the menu arrow should point to. |
| 47 | enum MenuArrowDirection { |
| 48 | LEFT_POINTING_ARROW, |
| 49 | RIGHT_POINTING_ARROW |
| 50 | }; |
| 51 | |
| 52 | typedef HRESULT (WINAPI* DrawThemeBackgroundPtr)(HANDLE theme, |
| 53 | HDC hdc, |
| 54 | int part_id, |
| 55 | int state_id, |
| 56 | const RECT* rect, |
| 57 | const RECT* clip_rect); |
| 58 | typedef HRESULT (WINAPI* DrawThemeBackgroundExPtr)(HANDLE theme, |
| 59 | HDC hdc, |
| 60 | int part_id, |
| 61 | int state_id, |
| 62 | const RECT* rect, |
| 63 | const DTBGOPTS* opts); |
| 64 | typedef HRESULT (WINAPI* GetThemeColorPtr)(HANDLE hTheme, |
| 65 | int part_id, |
| 66 | int state_id, |
| 67 | int prop_id, |
| 68 | COLORREF* color); |
| 69 | typedef HRESULT (WINAPI* GetThemeContentRectPtr)(HANDLE hTheme, |
| 70 | HDC hdc, |
| 71 | int part_id, |
| 72 | int state_id, |
| 73 | const RECT* rect, |
| 74 | RECT* content_rect); |
| 75 | typedef HRESULT (WINAPI* GetThemePartSizePtr)(HANDLE hTheme, |
| 76 | HDC hdc, |
| 77 | int part_id, |
| 78 | int state_id, |
| 79 | RECT* rect, |
| 80 | int ts, |
| 81 | SIZE* size); |
| 82 | typedef HANDLE (WINAPI* OpenThemeDataPtr)(HWND window, |
| 83 | LPCWSTR class_list); |
| 84 | typedef HRESULT (WINAPI* CloseThemeDataPtr)(HANDLE theme); |
| 85 | |
| 86 | typedef void (WINAPI* SetThemeAppPropertiesPtr) (DWORD flags); |
| 87 | typedef BOOL (WINAPI* IsThemeActivePtr)(); |
| 88 | typedef HRESULT (WINAPI* GetThemeIntPtr)(HANDLE hTheme, |
| 89 | int part_id, |
| 90 | int state_id, |
| 91 | int prop_id, |
| 92 | int *value); |
| 93 | |
| 94 | HRESULT PaintButton(HDC hdc, |
| 95 | int part_id, |
| 96 | int state_id, |
| 97 | int classic_state, |
| 98 | RECT* rect) const; |
| 99 | |
| 100 | HRESULT PaintTextField(HDC hdc, |
| 101 | int part_id, |
| 102 | int state_id, |
| 103 | int classic_state, |
| 104 | RECT* rect, |
| 105 | COLORREF color, |
| 106 | bool fill_content_area, |
| 107 | bool draw_edges) const; |
| 108 | |
| 109 | HRESULT PaintMenuList(HDC hdc, |
| 110 | int part_id, |
| 111 | int state_id, |
| 112 | int classic_state, |
| 113 | RECT* rect) const; |
| 114 | |
| 115 | // Paints a scrollbar arrow. |classic_state| should have the appropriate |
| 116 | // classic part number ORed in already. |
| 117 | HRESULT PaintScrollbarArrow(HDC hdc, |
| 118 | int state_id, |
| 119 | int classic_state, |
| 120 | RECT* rect) const; |
| 121 | |
| 122 | // Paints a scrollbar track section. |align_rect| is only used in classic |
| 123 | // mode, and makes sure the checkerboard pattern in |target_rect| is aligned |
| 124 | // with one presumed to be in |align_rect|. |
| 125 | HRESULT PaintScrollbarTrack(HDC hdc, |
| 126 | int part_id, |
| 127 | int state_id, |
| 128 | int classic_state, |
| 129 | RECT* target_rect, |
| 130 | RECT* align_rect, |
awalker@google.com | bce88e1 | 2008-08-15 02:47:00 +0900 | [diff] [blame] | 131 | PlatformCanvasWin* canvas) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 132 | |
| 133 | // |arrow_direction| determines whether the arrow is pointing to the left or |
| 134 | // to the right. In RTL locales, sub-menus open from right to left and |
| 135 | // therefore the menu arrow should point to the left and not to the right. |
| 136 | HRESULT PaintMenuArrow(ThemeName theme, |
| 137 | HDC hdc, |
| 138 | int part_id, |
| 139 | int state_id, |
| 140 | RECT* rect, |
| 141 | MenuArrowDirection arrow_direction, |
| 142 | bool is_highlighted) const; |
| 143 | |
| 144 | HRESULT PaintMenuBackground(ThemeName theme, |
| 145 | HDC hdc, |
| 146 | int part_id, |
| 147 | int state_id, |
| 148 | RECT* rect) const; |
| 149 | |
| 150 | HRESULT PaintMenuCheck(ThemeName theme, |
| 151 | HDC hdc, |
| 152 | int part_id, |
| 153 | int state_id, |
| 154 | RECT* rect, |
| 155 | bool is_highlighted) const; |
| 156 | |
| 157 | HRESULT PaintMenuCheckBackground(ThemeName theme, |
| 158 | HDC hdc, |
| 159 | int part_id, |
| 160 | int state_id, |
| 161 | RECT* rect) const; |
| 162 | |
| 163 | HRESULT PaintMenuGutter(HDC hdc, |
| 164 | int part_id, |
| 165 | int state_id, |
| 166 | RECT* rect) const; |
| 167 | |
| 168 | HRESULT PaintMenuSeparator(HDC hdc, |
| 169 | int part_id, |
| 170 | int state_id, |
| 171 | RECT* rect) const; |
| 172 | |
| 173 | HRESULT PaintMenuItemBackground(ThemeName theme, |
| 174 | HDC hdc, |
| 175 | int part_id, |
| 176 | int state_id, |
| 177 | bool selected, |
| 178 | RECT* rect) const; |
| 179 | |
| 180 | // Paints a scrollbar thumb or gripper. |
| 181 | HRESULT PaintScrollbarThumb(HDC hdc, |
| 182 | int part_id, |
| 183 | int state_id, |
| 184 | int classic_state, |
| 185 | RECT* rect) const; |
| 186 | |
| 187 | HRESULT PaintStatusGripper(HDC hdc, |
| 188 | int part_id, |
| 189 | int state_id, |
| 190 | int classic_state, |
| 191 | RECT* rect) const; |
| 192 | |
| 193 | HRESULT PaintDialogBackground(HDC dc, bool active, RECT* rect) const; |
| 194 | |
| 195 | HRESULT PaintTabPanelBackground(HDC dc, RECT* rect) const; |
| 196 | |
| 197 | HRESULT PaintListBackground(HDC dc, bool enabled, RECT* rect) const; |
| 198 | |
| 199 | bool IsThemingActive() const; |
| 200 | |
| 201 | HRESULT GetThemePartSize(ThemeName themeName, |
| 202 | HDC hdc, |
| 203 | int part_id, |
| 204 | int state_id, |
| 205 | RECT* rect, |
| 206 | int ts, |
| 207 | SIZE* size) const; |
| 208 | |
| 209 | HRESULT GetThemeColor(ThemeName theme, |
| 210 | int part_id, |
| 211 | int state_id, |
| 212 | int prop_id, |
| 213 | SkColor* color) const; |
| 214 | |
| 215 | // Get the theme color if theming is enabled. If theming is unsupported |
| 216 | // for this part, use Win32's GetSysColor to find the color specified |
| 217 | // by default_sys_color. |
| 218 | SkColor GetThemeColorWithDefault(ThemeName theme, |
| 219 | int part_id, |
| 220 | int state_id, |
| 221 | int prop_id, |
| 222 | int default_sys_color) const; |
| 223 | |
| 224 | HRESULT GetThemeInt(ThemeName theme, |
| 225 | int part_id, |
| 226 | int state_id, |
| 227 | int prop_id, |
| 228 | int *result) const; |
| 229 | |
| 230 | // Get the thickness of the border associated with the specified theme, |
| 231 | // defaulting to GetSystemMetrics edge size if themes are disabled. |
| 232 | // In Classic Windows, borders are typically 2px; on XP+, they are 1px. |
| 233 | Size GetThemeBorderSize(ThemeName theme) const; |
| 234 | |
| 235 | // Disables all theming for top-level windows in the entire process, from |
| 236 | // when this method is called until the process exits. All the other |
| 237 | // methods in this class will continue to work, but their output will ignore |
| 238 | // the user's theme. This is meant for use when running tests that require |
| 239 | // consistent visual results. |
| 240 | void DisableTheming() const; |
| 241 | |
| 242 | // Closes cached theme handles so we can unload the DLL or update our UI |
| 243 | // for a theme change. |
| 244 | void CloseHandles() const; |
| 245 | |
| 246 | // Gets our singleton instance. |
| 247 | static const NativeTheme* instance(); |
| 248 | |
| 249 | private: |
| 250 | NativeTheme(); |
| 251 | ~NativeTheme(); |
| 252 | |
| 253 | HRESULT PaintFrameControl(HDC hdc, |
| 254 | RECT* rect, |
| 255 | UINT type, |
| 256 | UINT state, |
| 257 | bool is_highlighted) const; |
| 258 | |
| 259 | // Returns a handle to the theme data. |
| 260 | HANDLE GetThemeHandle(ThemeName theme_name) const; |
| 261 | |
| 262 | // Function pointers into uxtheme.dll. |
| 263 | DrawThemeBackgroundPtr draw_theme_; |
| 264 | DrawThemeBackgroundExPtr draw_theme_ex_; |
| 265 | GetThemeColorPtr get_theme_color_; |
| 266 | GetThemeContentRectPtr get_theme_content_rect_; |
| 267 | GetThemePartSizePtr get_theme_part_size_; |
| 268 | OpenThemeDataPtr open_theme_; |
| 269 | CloseThemeDataPtr close_theme_; |
| 270 | SetThemeAppPropertiesPtr set_theme_properties_; |
| 271 | IsThemeActivePtr is_theme_active_; |
| 272 | GetThemeIntPtr get_theme_int_; |
| 273 | |
| 274 | // Handle to uxtheme.dll. |
| 275 | HMODULE theme_dll_; |
| 276 | |
| 277 | // A cache of open theme handles. |
| 278 | mutable HANDLE theme_handles_[LAST]; |
| 279 | |
| 280 | DISALLOW_EVIL_CONSTRUCTORS(NativeTheme); |
| 281 | }; |
| 282 | |
| 283 | } // namespace gfx |
| 284 | |
| 285 | #endif // BASE_GFX_NATIVE_THEME_H__ |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 286 | |