| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/views/controls/menu/menu.h" | 5 #include "chrome/views/controls/menu/menu.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlapp.h> | 8 #include <atlapp.h> |
| 9 #include <atlwin.h> | 9 #include <atlwin.h> |
| 10 #include <atlcrack.h> | 10 #include <atlcrack.h> |
| 11 #include <atlframe.h> | 11 #include <atlframe.h> |
| 12 #include <atlmisc.h> | 12 #include <atlmisc.h> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/gfx/rect.h" | 15 #include "base/gfx/rect.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "chrome/views/accelerator.h" | 17 #include "base/stl_util-inl.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "chrome/common/gfx/chrome_canvas.h" | 19 #include "chrome/common/gfx/chrome_canvas.h" |
| 20 #include "chrome/common/gfx/chrome_font.h" | 20 #include "chrome/common/gfx/chrome_font.h" |
| 21 #include "chrome/common/l10n_util.h" | 21 #include "chrome/common/l10n_util.h" |
| 22 #include "chrome/common/l10n_util_win.h" | 22 #include "chrome/common/l10n_util_win.h" |
| 23 #include "chrome/common/stl_util-inl.h" | 23 #include "chrome/views/accelerator.h" |
| 24 | 24 |
| 25 const SkBitmap* Menu::Delegate::kEmptyIcon = 0; | 25 const SkBitmap* Menu::Delegate::kEmptyIcon = 0; |
| 26 | 26 |
| 27 // The width of an icon, including the pixels between the icon and | 27 // The width of an icon, including the pixels between the icon and |
| 28 // the item label. | 28 // the item label. |
| 29 static const int kIconWidth = 23; | 29 static const int kIconWidth = 23; |
| 30 // Margins between the top of the item and the label. | 30 // Margins between the top of the item and the label. |
| 31 static const int kItemTopMargin = 3; | 31 static const int kItemTopMargin = 3; |
| 32 // Margins between the bottom of the item and the label. | 32 // Margins between the bottom of the item and the label. |
| 33 static const int kItemBottomMargin = 4; | 33 static const int kItemBottomMargin = 4; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 reinterpret_cast<Menu::ItemData*>(lpdis->itemData); | 144 reinterpret_cast<Menu::ItemData*>(lpdis->itemData); |
| 145 | 145 |
| 146 // Draw the background. | 146 // Draw the background. |
| 147 HBRUSH hbr = CreateSolidBrush(GetBkColor(hDC)); | 147 HBRUSH hbr = CreateSolidBrush(GetBkColor(hDC)); |
| 148 FillRect(hDC, &lpdis->rcItem, hbr); | 148 FillRect(hDC, &lpdis->rcItem, hbr); |
| 149 DeleteObject(hbr); | 149 DeleteObject(hbr); |
| 150 | 150 |
| 151 // Draw the label. | 151 // Draw the label. |
| 152 RECT rect = lpdis->rcItem; | 152 RECT rect = lpdis->rcItem; |
| 153 rect.top += kItemTopMargin; | 153 rect.top += kItemTopMargin; |
| 154 // Should we add kIconWidth only when icon.width() != 0 ? | 154 // Should we add kIconWidth only when icon.width() != 0 ? |
| 155 rect.left += kItemLeftMargin + kIconWidth; | 155 rect.left += kItemLeftMargin + kIconWidth; |
| 156 rect.right -= kItemRightMargin; | 156 rect.right -= kItemRightMargin; |
| 157 UINT format = DT_TOP | DT_SINGLELINE; | 157 UINT format = DT_TOP | DT_SINGLELINE; |
| 158 // Check whether the mnemonics should be underlined. | 158 // Check whether the mnemonics should be underlined. |
| 159 BOOL underline_mnemonics; | 159 BOOL underline_mnemonics; |
| 160 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &underline_mnemonics, 0); | 160 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &underline_mnemonics, 0); |
| 161 if (!underline_mnemonics) | 161 if (!underline_mnemonics) |
| 162 format |= DT_HIDEPREFIX; | 162 format |= DT_HIDEPREFIX; |
| 163 ChromeFont font; | 163 ChromeFont font; |
| 164 HGDIOBJ old_font = static_cast<HFONT>(SelectObject(hDC, font.hfont())); | 164 HGDIOBJ old_font = static_cast<HFONT>(SelectObject(hDC, font.hfont())); |
| 165 int fontsize = font.FontSize(); | 165 int fontsize = font.FontSize(); |
| 166 | 166 |
| 167 // If an accelerator is specified (with a tab delimiting the rest | 167 // If an accelerator is specified (with a tab delimiting the rest of the |
| 168 // of the label from the accelerator), we have to justify | 168 // label from the accelerator), we have to justify the fist part on the |
| 169 // the fist part on the left and the accelerator on the right. | 169 // left and the accelerator on the right. |
| 170 // TODO(jungshik): This will break in RTL UI. Currently, he/ar | 170 // TODO(jungshik): This will break in RTL UI. Currently, he/ar use the |
| 171 // use the window system UI font and will not hit here. | 171 // window system UI font and will not hit here. |
| 172 std::wstring label = data->label; | 172 std::wstring label = data->label; |
| 173 std::wstring accel; | 173 std::wstring accel; |
| 174 std::wstring::size_type tab_pos = label.find(L'\t'); | 174 std::wstring::size_type tab_pos = label.find(L'\t'); |
| 175 if (tab_pos != std::wstring::npos) { | 175 if (tab_pos != std::wstring::npos) { |
| 176 accel = label.substr(tab_pos); | 176 accel = label.substr(tab_pos); |
| 177 label = label.substr(0, tab_pos); | 177 label = label.substr(0, tab_pos); |
| 178 } | 178 } |
| 179 DrawTextEx(hDC, const_cast<wchar_t*>(label.data()), | 179 DrawTextEx(hDC, const_cast<wchar_t*>(label.data()), |
| 180 static_cast<int>(label.size()), &rect, format | DT_LEFT, NULL); | 180 static_cast<int>(label.size()), &rect, format | DT_LEFT, NULL); |
| 181 if (!accel.empty()) | 181 if (!accel.empty()) |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 } | 617 } |
| 618 | 618 |
| 619 void Menu::Cancel() { | 619 void Menu::Cancel() { |
| 620 DCHECK(is_menu_visible_); | 620 DCHECK(is_menu_visible_); |
| 621 EndMenu(); | 621 EndMenu(); |
| 622 } | 622 } |
| 623 | 623 |
| 624 int Menu::ItemCount() { | 624 int Menu::ItemCount() { |
| 625 return GetMenuItemCount(menu_); | 625 return GetMenuItemCount(menu_); |
| 626 } | 626 } |
| OLD | NEW |