OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/native_theme_win.h" | 5 #include "ui/gfx/native_theme_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
9 #include <vsstyle.h> | 9 #include <vsstyle.h> |
10 #include <vssym32.h> | 10 #include <vssym32.h> |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 NULL); | 628 NULL); |
629 } else { | 629 } else { |
630 // There is no way to tell the uxtheme API to draw a left pointing arrow; | 630 // There is no way to tell the uxtheme API to draw a left pointing arrow; |
631 // it doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they | 631 // it doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they |
632 // are needed for RTL locales on Vista. So use a memory DC and mirror | 632 // are needed for RTL locales on Vista. So use a memory DC and mirror |
633 // the region with GDI's StretchBlt. | 633 // the region with GDI's StretchBlt. |
634 Rect r(rect); | 634 Rect r(rect); |
635 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc)); | 635 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc)); |
636 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(), | 636 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(), |
637 r.height())); | 637 r.height())); |
638 base::win::ScopedSelectObject select_bitmap(mem_dc, mem_bitmap); | 638 base::win::ScopedSelectObject select_bitmap(mem_dc.get(), mem_bitmap); |
639 // Copy and horizontally mirror the background from hdc into mem_dc. Use | 639 // Copy and horizontally mirror the background from hdc into mem_dc. Use |
640 // a negative-width source rect, starting at the rightmost pixel. | 640 // a negative-width source rect, starting at the rightmost pixel. |
641 StretchBlt(mem_dc, 0, 0, r.width(), r.height(), | 641 StretchBlt(mem_dc.get(), 0, 0, r.width(), r.height(), |
642 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY); | 642 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY); |
643 // Draw the arrow. | 643 // Draw the arrow. |
644 RECT theme_rect = {0, 0, r.width(), r.height()}; | 644 RECT theme_rect = {0, 0, r.width(), r.height()}; |
645 HRESULT result = draw_theme_(handle, mem_dc, MENU_POPUPSUBMENU, | 645 HRESULT result = draw_theme_(handle, mem_dc.get(), MENU_POPUPSUBMENU, |
646 state_id, &theme_rect, NULL); | 646 state_id, &theme_rect, NULL); |
647 // Copy and mirror the result back into mem_dc. | 647 // Copy and mirror the result back into mem_dc. |
648 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(), | 648 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(), |
649 mem_dc, r.width()-1, 0, -r.width(), r.height(), SRCCOPY); | 649 mem_dc.get(), r.width()-1, 0, -r.width(), r.height(), SRCCOPY); |
650 return result; | 650 return result; |
651 } | 651 } |
652 } | 652 } |
653 | 653 |
654 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a | 654 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a |
655 // left pointing arrow. This makes the following 'if' statement slightly | 655 // left pointing arrow. This makes the following 'if' statement slightly |
656 // counterintuitive. | 656 // counterintuitive. |
657 UINT pfc_state; | 657 UINT pfc_state; |
658 if (extra.pointing_right) | 658 if (extra.pointing_right) |
659 pfc_state = DFCS_MENUARROW; | 659 pfc_state = DFCS_MENUARROW; |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 const int width = rect.width(); | 1661 const int width = rect.width(); |
1662 const int height = rect.height(); | 1662 const int height = rect.height(); |
1663 | 1663 |
1664 // DrawFrameControl for menu arrow/check wants a monochrome bitmap. | 1664 // DrawFrameControl for menu arrow/check wants a monochrome bitmap. |
1665 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL)); | 1665 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL)); |
1666 | 1666 |
1667 if (mask_bitmap == NULL) | 1667 if (mask_bitmap == NULL) |
1668 return E_OUTOFMEMORY; | 1668 return E_OUTOFMEMORY; |
1669 | 1669 |
1670 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL)); | 1670 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL)); |
1671 base::win::ScopedSelectObject select_bitmap(bitmap_dc, mask_bitmap); | 1671 base::win::ScopedSelectObject select_bitmap(bitmap_dc.get(), mask_bitmap); |
1672 RECT local_rect = { 0, 0, width, height }; | 1672 RECT local_rect = { 0, 0, width, height }; |
1673 DrawFrameControl(bitmap_dc, &local_rect, type, state); | 1673 DrawFrameControl(bitmap_dc.get(), &local_rect, type, state); |
1674 | 1674 |
1675 // We're going to use BitBlt with a b&w mask. This results in using the dest | 1675 // We're going to use BitBlt with a b&w mask. This results in using the dest |
1676 // dc's text color for the black bits in the mask, and the dest dc's | 1676 // dc's text color for the black bits in the mask, and the dest dc's |
1677 // background color for the white bits in the mask. DrawFrameControl draws the | 1677 // background color for the white bits in the mask. DrawFrameControl draws the |
1678 // check in black, and the background in white. | 1678 // check in black, and the background in white. |
1679 int bg_color_key; | 1679 int bg_color_key; |
1680 int text_color_key; | 1680 int text_color_key; |
1681 switch (control_state) { | 1681 switch (control_state) { |
1682 case gfx::NativeTheme::kHovered: | 1682 case gfx::NativeTheme::kHovered: |
1683 bg_color_key = COLOR_HIGHLIGHT; | 1683 bg_color_key = COLOR_HIGHLIGHT; |
1684 text_color_key = COLOR_HIGHLIGHTTEXT; | 1684 text_color_key = COLOR_HIGHLIGHTTEXT; |
1685 break; | 1685 break; |
1686 case gfx::NativeTheme::kNormal: | 1686 case gfx::NativeTheme::kNormal: |
1687 bg_color_key = COLOR_MENU; | 1687 bg_color_key = COLOR_MENU; |
1688 text_color_key = COLOR_MENUTEXT; | 1688 text_color_key = COLOR_MENUTEXT; |
1689 break; | 1689 break; |
1690 case gfx::NativeTheme::kDisabled: | 1690 case gfx::NativeTheme::kDisabled: |
1691 bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU; | 1691 bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU; |
1692 text_color_key = COLOR_GRAYTEXT; | 1692 text_color_key = COLOR_GRAYTEXT; |
1693 break; | 1693 break; |
1694 default: | 1694 default: |
1695 NOTREACHED(); | 1695 NOTREACHED(); |
1696 bg_color_key = COLOR_MENU; | 1696 bg_color_key = COLOR_MENU; |
1697 text_color_key = COLOR_MENUTEXT; | 1697 text_color_key = COLOR_MENUTEXT; |
1698 break; | 1698 break; |
1699 } | 1699 } |
1700 COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key)); | 1700 COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key)); |
1701 COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key)); | 1701 COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key)); |
1702 BitBlt(hdc, rect.x(), rect.y(), width, height, bitmap_dc, 0, 0, SRCCOPY); | 1702 BitBlt(hdc, |
| 1703 rect.x(), rect.y(), width, height, |
| 1704 bitmap_dc.get(), |
| 1705 0, 0, |
| 1706 SRCCOPY); |
1703 SetBkColor(hdc, old_bg_color); | 1707 SetBkColor(hdc, old_bg_color); |
1704 SetTextColor(hdc, old_text_color); | 1708 SetTextColor(hdc, old_text_color); |
1705 | 1709 |
1706 return S_OK; | 1710 return S_OK; |
1707 } | 1711 } |
1708 | 1712 |
1709 HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const { | 1713 HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const { |
1710 if (!open_theme_ || theme_name < 0 || theme_name >= LAST) | 1714 if (!open_theme_ || theme_name < 0 || theme_name >= LAST) |
1711 return 0; | 1715 return 0; |
1712 | 1716 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 handle = open_theme_(NULL, L"Spin"); | 1757 handle = open_theme_(NULL, L"Spin"); |
1754 break; | 1758 break; |
1755 default: | 1759 default: |
1756 NOTREACHED(); | 1760 NOTREACHED(); |
1757 } | 1761 } |
1758 theme_handles_[theme_name] = handle; | 1762 theme_handles_[theme_name] = handle; |
1759 return handle; | 1763 return handle; |
1760 } | 1764 } |
1761 | 1765 |
1762 } // namespace gfx | 1766 } // namespace gfx |
OLD | NEW |