| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/menu/native_menu_win.h" | 5 #include "views/controls/menu/native_menu_win.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/l10n_util_win.h" | 8 #include "app/l10n_util_win.h" |
| 9 #include "base/keyboard_codes.h" | 9 #include "base/keyboard_codes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 gfx::Font font; | 144 gfx::Font font; |
| 145 measure_item_struct->itemWidth = font.GetStringWidth(data->label) + | 145 measure_item_struct->itemWidth = font.GetStringWidth(data->label) + |
| 146 kIconWidth + kItemLeftMargin + kItemRightMargin - | 146 kIconWidth + kItemLeftMargin + kItemRightMargin - |
| 147 GetSystemMetrics(SM_CXMENUCHECK); | 147 GetSystemMetrics(SM_CXMENUCHECK); |
| 148 if (data->submenu.get()) | 148 if (data->submenu.get()) |
| 149 measure_item_struct->itemWidth += kArrowWidth; | 149 measure_item_struct->itemWidth += kArrowWidth; |
| 150 // If the label contains an accelerator, make room for tab. | 150 // If the label contains an accelerator, make room for tab. |
| 151 if (data->label.find(L'\t') != std::wstring::npos) | 151 if (data->label.find(L'\t') != std::wstring::npos) |
| 152 measure_item_struct->itemWidth += font.GetStringWidth(L" "); | 152 measure_item_struct->itemWidth += font.GetStringWidth(L" "); |
| 153 measure_item_struct->itemHeight = | 153 measure_item_struct->itemHeight = |
| 154 font.height() + kItemBottomMargin + kItemTopMargin; | 154 font.GetHeight() + kItemBottomMargin + kItemTopMargin; |
| 155 } else { | 155 } else { |
| 156 // Measure separator size. | 156 // Measure separator size. |
| 157 measure_item_struct->itemHeight = GetSystemMetrics(SM_CYMENU) / 2; | 157 measure_item_struct->itemHeight = GetSystemMetrics(SM_CYMENU) / 2; |
| 158 measure_item_struct->itemWidth = 0; | 158 measure_item_struct->itemWidth = 0; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Called by Windows to paint an owner-drawn menu item. | 162 // Called by Windows to paint an owner-drawn menu item. |
| 163 void OnDrawItem(UINT w_param, DRAWITEMSTRUCT* draw_item_struct) { | 163 void OnDrawItem(UINT w_param, DRAWITEMSTRUCT* draw_item_struct) { |
| 164 HDC dc = draw_item_struct->hDC; | 164 HDC dc = draw_item_struct->hDC; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 189 // Should we add kIconWidth only when icon.width() != 0 ? | 189 // Should we add kIconWidth only when icon.width() != 0 ? |
| 190 rect.left += kItemLeftMargin + kIconWidth; | 190 rect.left += kItemLeftMargin + kIconWidth; |
| 191 rect.right -= kItemRightMargin; | 191 rect.right -= kItemRightMargin; |
| 192 UINT format = DT_TOP | DT_SINGLELINE; | 192 UINT format = DT_TOP | DT_SINGLELINE; |
| 193 // Check whether the mnemonics should be underlined. | 193 // Check whether the mnemonics should be underlined. |
| 194 BOOL underline_mnemonics; | 194 BOOL underline_mnemonics; |
| 195 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &underline_mnemonics, 0); | 195 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &underline_mnemonics, 0); |
| 196 if (!underline_mnemonics) | 196 if (!underline_mnemonics) |
| 197 format |= DT_HIDEPREFIX; | 197 format |= DT_HIDEPREFIX; |
| 198 gfx::Font font; | 198 gfx::Font font; |
| 199 HGDIOBJ old_font = static_cast<HFONT>(SelectObject(dc, font.hfont())); | 199 HGDIOBJ old_font = |
| 200 int fontsize = font.FontSize(); | 200 static_cast<HFONT>(SelectObject(dc, font.GetNativeFont())); |
| 201 int fontsize = font.GetFontSize(); |
| 201 | 202 |
| 202 // If an accelerator is specified (with a tab delimiting the rest of the | 203 // If an accelerator is specified (with a tab delimiting the rest of the |
| 203 // label from the accelerator), we have to justify the fist part on the | 204 // label from the accelerator), we have to justify the fist part on the |
| 204 // left and the accelerator on the right. | 205 // left and the accelerator on the right. |
| 205 // TODO(jungshik): This will break in RTL UI. Currently, he/ar use the | 206 // TODO(jungshik): This will break in RTL UI. Currently, he/ar use the |
| 206 // window system UI font and will not hit here. | 207 // window system UI font and will not hit here. |
| 207 std::wstring label = data->label; | 208 std::wstring label = data->label; |
| 208 std::wstring accel; | 209 std::wstring accel; |
| 209 std::wstring::size_type tab_pos = label.find(L'\t'); | 210 std::wstring::size_type tab_pos = label.find(L'\t'); |
| 210 if (tab_pos != std::wstring::npos) { | 211 if (tab_pos != std::wstring::npos) { |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 629 |
| 629 //////////////////////////////////////////////////////////////////////////////// | 630 //////////////////////////////////////////////////////////////////////////////// |
| 630 // MenuWrapper, public: | 631 // MenuWrapper, public: |
| 631 | 632 |
| 632 // static | 633 // static |
| 633 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { | 634 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { |
| 634 return new NativeMenuWin(menu->model(), NULL); | 635 return new NativeMenuWin(menu->model(), NULL); |
| 635 } | 636 } |
| 636 | 637 |
| 637 } // namespace views | 638 } // namespace views |
| OLD | NEW |