| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #ifndef UI_BASE_NATIVE_THEME_NATIVE_THEME_WIN_H_ | |
| 6 #define UI_BASE_NATIVE_THEME_NATIVE_THEME_WIN_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 // A wrapper class for working with custom XP/Vista themes provided in | |
| 10 // uxtheme.dll. This is a singleton class that can be grabbed using | |
| 11 // NativeThemeWin::instance(). | |
| 12 // For more information on visual style parts and states, see: | |
| 13 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/plat
form/commctls/userex/topics/partsandstates.asp | |
| 14 | |
| 15 #include <windows.h> | |
| 16 #include <uxtheme.h> | |
| 17 | |
| 18 #include "base/basictypes.h" | |
| 19 #include "base/compiler_specific.h" | |
| 20 #include "third_party/skia/include/core/SkColor.h" | |
| 21 #include "ui/base/native_theme/native_theme.h" | |
| 22 #include "ui/gfx/size.h" | |
| 23 | |
| 24 class SkCanvas; | |
| 25 | |
| 26 namespace ui { | |
| 27 | |
| 28 // Windows implementation of native theme class. | |
| 29 // | |
| 30 // At the moment, this class in in transition from an older API that consists | |
| 31 // of several PaintXXX methods to an API, inherited from the NativeTheme base | |
| 32 // class, that consists of a single Paint() method with a argument to indicate | |
| 33 // what kind of part to paint. | |
| 34 class UI_EXPORT NativeThemeWin : public NativeTheme { | |
| 35 public: | |
| 36 enum ThemeName { | |
| 37 BUTTON, | |
| 38 LIST, | |
| 39 MENU, | |
| 40 MENULIST, | |
| 41 SCROLLBAR, | |
| 42 STATUS, | |
| 43 TAB, | |
| 44 TEXTFIELD, | |
| 45 TRACKBAR, | |
| 46 WINDOW, | |
| 47 PROGRESS, | |
| 48 SPIN, | |
| 49 LAST | |
| 50 }; | |
| 51 | |
| 52 bool IsThemingActive() const; | |
| 53 | |
| 54 HRESULT GetThemeColor(ThemeName theme, | |
| 55 int part_id, | |
| 56 int state_id, | |
| 57 int prop_id, | |
| 58 SkColor* color) const; | |
| 59 | |
| 60 // Get the theme color if theming is enabled. If theming is unsupported | |
| 61 // for this part, use Win32's GetSysColor to find the color specified | |
| 62 // by default_sys_color. | |
| 63 SkColor GetThemeColorWithDefault(ThemeName theme, | |
| 64 int part_id, | |
| 65 int state_id, | |
| 66 int prop_id, | |
| 67 int default_sys_color) const; | |
| 68 | |
| 69 // Get the thickness of the border associated with the specified theme, | |
| 70 // defaulting to GetSystemMetrics edge size if themes are disabled. | |
| 71 // In Classic Windows, borders are typically 2px; on XP+, they are 1px. | |
| 72 gfx::Size GetThemeBorderSize(ThemeName theme) const; | |
| 73 | |
| 74 // Disables all theming for top-level windows in the entire process, from | |
| 75 // when this method is called until the process exits. All the other | |
| 76 // methods in this class will continue to work, but their output will ignore | |
| 77 // the user's theme. This is meant for use when running tests that require | |
| 78 // consistent visual results. | |
| 79 void DisableTheming() const; | |
| 80 | |
| 81 // Closes cached theme handles so we can unload the DLL or update our UI | |
| 82 // for a theme change. | |
| 83 void CloseHandles() const; | |
| 84 | |
| 85 // Returns true if classic theme is in use. | |
| 86 bool IsClassicTheme(ThemeName name) const; | |
| 87 | |
| 88 // Gets our singleton instance. | |
| 89 static const NativeThemeWin* instance(); | |
| 90 | |
| 91 HRESULT PaintTextField(HDC hdc, | |
| 92 int part_id, | |
| 93 int state_id, | |
| 94 int classic_state, | |
| 95 RECT* rect, | |
| 96 COLORREF color, | |
| 97 bool fill_content_area, | |
| 98 bool draw_edges) const; | |
| 99 | |
| 100 private: | |
| 101 NativeThemeWin(); | |
| 102 ~NativeThemeWin(); | |
| 103 | |
| 104 // NativeTheme Implementation: | |
| 105 virtual gfx::Size GetPartSize(Part part, | |
| 106 State state, | |
| 107 const ExtraParams& extra) const OVERRIDE; | |
| 108 virtual void Paint(SkCanvas* canvas, | |
| 109 Part part, | |
| 110 State state, | |
| 111 const gfx::Rect& rect, | |
| 112 const ExtraParams& extra) const OVERRIDE; | |
| 113 virtual SkColor GetSystemColor(ColorId color_id) const OVERRIDE; | |
| 114 | |
| 115 void PaintToNonPlatformCanvas(SkCanvas* canvas, | |
| 116 Part part, | |
| 117 State state, | |
| 118 const gfx::Rect& rect, | |
| 119 const ExtraParams& extra) const; | |
| 120 | |
| 121 HRESULT GetThemePartSize(ThemeName themeName, | |
| 122 HDC hdc, | |
| 123 int part_id, | |
| 124 int state_id, | |
| 125 RECT* rect, | |
| 126 int ts, | |
| 127 SIZE* size) const; | |
| 128 | |
| 129 HRESULT PaintButton(HDC hdc, | |
| 130 State state, | |
| 131 const ButtonExtraParams& extra, | |
| 132 int part_id, | |
| 133 int state_id, | |
| 134 RECT* rect) const; | |
| 135 | |
| 136 HRESULT PaintMenuSeparator(HDC hdc, | |
| 137 const gfx::Rect& rect, | |
| 138 const MenuSeparatorExtraParams& extra) const; | |
| 139 | |
| 140 HRESULT PaintMenuGutter(HDC hdc, const gfx::Rect& rect) const; | |
| 141 | |
| 142 // |arrow_direction| determines whether the arrow is pointing to the left or | |
| 143 // to the right. In RTL locales, sub-menus open from right to left and | |
| 144 // therefore the menu arrow should point to the left and not to the right. | |
| 145 HRESULT PaintMenuArrow(HDC hdc, | |
| 146 State state, | |
| 147 const gfx::Rect& rect, | |
| 148 const MenuArrowExtraParams& extra) const; | |
| 149 | |
| 150 HRESULT PaintMenuBackground(HDC hdc, const gfx::Rect& rect) const; | |
| 151 | |
| 152 HRESULT PaintMenuCheck(HDC hdc, | |
| 153 State state, | |
| 154 const gfx::Rect& rect, | |
| 155 const MenuCheckExtraParams& extra) const; | |
| 156 | |
| 157 HRESULT PaintMenuCheckBackground(HDC hdc, | |
| 158 State state, | |
| 159 const gfx::Rect& rect) const; | |
| 160 | |
| 161 HRESULT PaintMenuItemBackground(HDC hdc, | |
| 162 State state, | |
| 163 const gfx::Rect& rect, | |
| 164 const MenuItemExtraParams& extra) const; | |
| 165 | |
| 166 HRESULT PaintPushButton(HDC hdc, | |
| 167 Part part, | |
| 168 State state, | |
| 169 const gfx::Rect& rect, | |
| 170 const ButtonExtraParams& extra) const; | |
| 171 | |
| 172 HRESULT PaintRadioButton(HDC hdc, | |
| 173 Part part, | |
| 174 State state, | |
| 175 const gfx::Rect& rect, | |
| 176 const ButtonExtraParams& extra) const; | |
| 177 | |
| 178 HRESULT PaintCheckbox(HDC hdc, | |
| 179 Part part, | |
| 180 State state, | |
| 181 const gfx::Rect& rect, | |
| 182 const ButtonExtraParams& extra) const; | |
| 183 | |
| 184 HRESULT PaintMenuList(HDC hdc, | |
| 185 State state, | |
| 186 const gfx::Rect& rect, | |
| 187 const MenuListExtraParams& extra) const; | |
| 188 | |
| 189 // Paints a scrollbar arrow. |classic_state| should have the appropriate | |
| 190 // classic part number ORed in already. | |
| 191 HRESULT PaintScrollbarArrow(HDC hdc, | |
| 192 Part part, | |
| 193 State state, | |
| 194 const gfx::Rect& rect, | |
| 195 const ScrollbarArrowExtraParams& extra) const; | |
| 196 | |
| 197 HRESULT PaintScrollbarThumb(HDC hdc, | |
| 198 Part part, | |
| 199 State state, | |
| 200 const gfx::Rect& rect, | |
| 201 const ScrollbarThumbExtraParams& extra) const; | |
| 202 | |
| 203 // This method is deprecated and will be removed in the near future. | |
| 204 // Paints a scrollbar track section. |align_rect| is only used in classic | |
| 205 // mode, and makes sure the checkerboard pattern in |target_rect| is aligned | |
| 206 // with one presumed to be in |align_rect|. | |
| 207 HRESULT PaintScrollbarTrack(SkCanvas* canvas, | |
| 208 HDC hdc, | |
| 209 Part part, | |
| 210 State state, | |
| 211 const gfx::Rect& rect, | |
| 212 const ScrollbarTrackExtraParams& extra) const; | |
| 213 | |
| 214 HRESULT PaintSpinButton(HDC hdc, | |
| 215 Part part, | |
| 216 State state, | |
| 217 const gfx::Rect& rect, | |
| 218 const InnerSpinButtonExtraParams& extra) const; | |
| 219 | |
| 220 HRESULT PaintTrackbar(SkCanvas* canvas, | |
| 221 HDC hdc, | |
| 222 Part part, | |
| 223 State state, | |
| 224 const gfx::Rect& rect, | |
| 225 const TrackbarExtraParams& extra) const; | |
| 226 | |
| 227 HRESULT PaintProgressBar(HDC hdc, | |
| 228 const gfx::Rect& rect, | |
| 229 const ProgressBarExtraParams& extra) const; | |
| 230 | |
| 231 HRESULT PaintWindowResizeGripper(HDC hdc, const gfx::Rect& rect) const; | |
| 232 | |
| 233 HRESULT PaintTabPanelBackground(HDC hdc, const gfx::Rect& rect) const; | |
| 234 | |
| 235 HRESULT PaintTextField(HDC hdc, | |
| 236 Part part, | |
| 237 State state, | |
| 238 const gfx::Rect& rect, | |
| 239 const TextFieldExtraParams& extra) const; | |
| 240 | |
| 241 | |
| 242 // Get the windows theme name/part/state. These three helper functions are | |
| 243 // used only by GetPartSize(), as each of the corresponding PaintXXX() | |
| 244 // methods do further validation of the part and state that is required for | |
| 245 // getting the size. | |
| 246 static ThemeName GetThemeName(Part part); | |
| 247 static int GetWindowsPart(Part part, State state, const ExtraParams& extra); | |
| 248 static int GetWindowsState(Part part, State state, const ExtraParams& extra); | |
| 249 | |
| 250 HRESULT GetThemeInt(ThemeName theme, | |
| 251 int part_id, | |
| 252 int state_id, | |
| 253 int prop_id, | |
| 254 int *result) const; | |
| 255 | |
| 256 HRESULT PaintFrameControl(HDC hdc, | |
| 257 const gfx::Rect& rect, | |
| 258 UINT type, | |
| 259 UINT state, | |
| 260 bool is_selected, | |
| 261 State control_state) const; | |
| 262 | |
| 263 // Returns a handle to the theme data. | |
| 264 HANDLE GetThemeHandle(ThemeName theme_name) const; | |
| 265 | |
| 266 typedef HRESULT (WINAPI* DrawThemeBackgroundPtr)(HANDLE theme, | |
| 267 HDC hdc, | |
| 268 int part_id, | |
| 269 int state_id, | |
| 270 const RECT* rect, | |
| 271 const RECT* clip_rect); | |
| 272 typedef HRESULT (WINAPI* DrawThemeBackgroundExPtr)(HANDLE theme, | |
| 273 HDC hdc, | |
| 274 int part_id, | |
| 275 int state_id, | |
| 276 const RECT* rect, | |
| 277 const DTBGOPTS* opts); | |
| 278 typedef HRESULT (WINAPI* GetThemeColorPtr)(HANDLE hTheme, | |
| 279 int part_id, | |
| 280 int state_id, | |
| 281 int prop_id, | |
| 282 COLORREF* color); | |
| 283 typedef HRESULT (WINAPI* GetThemeContentRectPtr)(HANDLE hTheme, | |
| 284 HDC hdc, | |
| 285 int part_id, | |
| 286 int state_id, | |
| 287 const RECT* rect, | |
| 288 RECT* content_rect); | |
| 289 typedef HRESULT (WINAPI* GetThemePartSizePtr)(HANDLE hTheme, | |
| 290 HDC hdc, | |
| 291 int part_id, | |
| 292 int state_id, | |
| 293 RECT* rect, | |
| 294 int ts, | |
| 295 SIZE* size); | |
| 296 typedef HANDLE (WINAPI* OpenThemeDataPtr)(HWND window, | |
| 297 LPCWSTR class_list); | |
| 298 typedef HRESULT (WINAPI* CloseThemeDataPtr)(HANDLE theme); | |
| 299 | |
| 300 typedef void (WINAPI* SetThemeAppPropertiesPtr) (DWORD flags); | |
| 301 typedef BOOL (WINAPI* IsThemeActivePtr)(); | |
| 302 typedef HRESULT (WINAPI* GetThemeIntPtr)(HANDLE hTheme, | |
| 303 int part_id, | |
| 304 int state_id, | |
| 305 int prop_id, | |
| 306 int *value); | |
| 307 | |
| 308 // Function pointers into uxtheme.dll. | |
| 309 DrawThemeBackgroundPtr draw_theme_; | |
| 310 DrawThemeBackgroundExPtr draw_theme_ex_; | |
| 311 GetThemeColorPtr get_theme_color_; | |
| 312 GetThemeContentRectPtr get_theme_content_rect_; | |
| 313 GetThemePartSizePtr get_theme_part_size_; | |
| 314 OpenThemeDataPtr open_theme_; | |
| 315 CloseThemeDataPtr close_theme_; | |
| 316 SetThemeAppPropertiesPtr set_theme_properties_; | |
| 317 IsThemeActivePtr is_theme_active_; | |
| 318 GetThemeIntPtr get_theme_int_; | |
| 319 | |
| 320 // Handle to uxtheme.dll. | |
| 321 HMODULE theme_dll_; | |
| 322 | |
| 323 // A cache of open theme handles. | |
| 324 mutable HANDLE theme_handles_[LAST]; | |
| 325 | |
| 326 DISALLOW_COPY_AND_ASSIGN(NativeThemeWin); | |
| 327 }; | |
| 328 | |
| 329 } // namespace ui | |
| 330 | |
| 331 #endif // UI_BASE_NATIVE_THEME_NATIVE_THEME_WIN_H_ | |
| OLD | NEW |