Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/views/controls/menu/menu.cc

Issue 62064: UI font localization part 2 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/views/controls/menu/chrome_menu.cc ('k') | chrome/views/controls/table/table_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 void OnMeasureItem(WPARAM w_param, MEASUREITEMSTRUCT* lpmis) { 106 void OnMeasureItem(WPARAM w_param, MEASUREITEMSTRUCT* lpmis) {
107 Menu::ItemData* data = reinterpret_cast<Menu::ItemData*>(lpmis->itemData); 107 Menu::ItemData* data = reinterpret_cast<Menu::ItemData*>(lpmis->itemData);
108 if (data != NULL) { 108 if (data != NULL) {
109 ChromeFont font; 109 ChromeFont font;
110 lpmis->itemWidth = font.GetStringWidth(data->label) + kIconWidth + 110 lpmis->itemWidth = font.GetStringWidth(data->label) + kIconWidth +
111 kItemLeftMargin + kItemRightMargin - 111 kItemLeftMargin + kItemRightMargin -
112 GetSystemMetrics(SM_CXMENUCHECK); 112 GetSystemMetrics(SM_CXMENUCHECK);
113 if (data->submenu) 113 if (data->submenu)
114 lpmis->itemWidth += kArrowWidth; 114 lpmis->itemWidth += kArrowWidth;
115 // If the label contains an accelerator, make room for tab.
116 if (data->label.find(L'\t') != std::wstring::npos)
117 lpmis->itemWidth += font.GetStringWidth(L" ");
115 lpmis->itemHeight = font.height() + kItemBottomMargin + kItemTopMargin; 118 lpmis->itemHeight = font.height() + kItemBottomMargin + kItemTopMargin;
116 } else { 119 } else {
117 // Measure separator size. 120 // Measure separator size.
118 lpmis->itemHeight = GetSystemMetrics(SM_CYMENU) / 2; 121 lpmis->itemHeight = GetSystemMetrics(SM_CYMENU) / 2;
119 lpmis->itemWidth = 0; 122 lpmis->itemWidth = 0;
120 } 123 }
121 } 124 }
122 125
123 void OnDrawItem(UINT wParam, DRAWITEMSTRUCT* lpdis) { 126 void OnDrawItem(UINT wParam, DRAWITEMSTRUCT* lpdis) {
124 HDC hDC = lpdis->hDC; 127 HDC hDC = lpdis->hDC;
125 COLORREF prev_bg_color, prev_text_color; 128 COLORREF prev_bg_color, prev_text_color;
126 129
127 // Set background color and text color 130 // Set background color and text color
128 if (lpdis->itemState & ODS_SELECTED) { 131 if (lpdis->itemState & ODS_SELECTED) {
129 prev_bg_color = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT)); 132 prev_bg_color = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
130 prev_text_color = SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); 133 prev_text_color = SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
131 } else { 134 } else {
132 prev_bg_color = SetBkColor(hDC, GetSysColor(COLOR_MENU)); 135 prev_bg_color = SetBkColor(hDC, GetSysColor(COLOR_MENU));
133 if (lpdis->itemState & ODS_DISABLED) 136 if (lpdis->itemState & ODS_DISABLED)
134 prev_text_color = SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT)); 137 prev_text_color = SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
135 else 138 else
136 prev_text_color = SetTextColor(hDC, GetSysColor(COLOR_MENUTEXT)); 139 prev_text_color = SetTextColor(hDC, GetSysColor(COLOR_MENUTEXT));
137 } 140 }
138 141
139 if (lpdis->itemData) { 142 if (lpdis->itemData) {
140 Menu::ItemData* data = 143 Menu::ItemData* data =
141 reinterpret_cast<Menu::ItemData*>(lpdis->itemData); 144 reinterpret_cast<Menu::ItemData*>(lpdis->itemData);
142 wchar_t* str = const_cast<wchar_t*>(data->label.c_str());
143 145
144 // Draw the background. 146 // Draw the background.
145 HBRUSH hbr = CreateSolidBrush(GetBkColor(hDC)); 147 HBRUSH hbr = CreateSolidBrush(GetBkColor(hDC));
146 FillRect(hDC, &lpdis->rcItem, hbr); 148 FillRect(hDC, &lpdis->rcItem, hbr);
147 DeleteObject(hbr); 149 DeleteObject(hbr);
148 150
149 // Draw the label. 151 // Draw the label.
150 RECT rect = lpdis->rcItem; 152 RECT rect = lpdis->rcItem;
151 rect.top += kItemTopMargin; 153 rect.top += kItemTopMargin;
154 // Should we add kIconWidth only when icon.width() != 0 ?
152 rect.left += kItemLeftMargin + kIconWidth; 155 rect.left += kItemLeftMargin + kIconWidth;
153 UINT format = DT_TOP | DT_LEFT | DT_SINGLELINE; 156 rect.right -= kItemRightMargin;
157 UINT format = DT_TOP | DT_SINGLELINE;
154 // Check whether the mnemonics should be underlined. 158 // Check whether the mnemonics should be underlined.
155 BOOL underline_mnemonics; 159 BOOL underline_mnemonics;
156 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &underline_mnemonics, 0); 160 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &underline_mnemonics, 0);
157 if (!underline_mnemonics) 161 if (!underline_mnemonics)
158 format |= DT_HIDEPREFIX; 162 format |= DT_HIDEPREFIX;
159 DrawTextEx(hDC, str, static_cast<int>(data->label.size()), 163 ChromeFont font;
160 &rect, format, NULL); 164 HGDIOBJ old_font = static_cast<HFONT>(SelectObject(hDC, font.hfont()));
165 int fontsize = font.FontSize();
166
167 // If an accelerator is specified (with a tab delimiting the rest
168 // of the label from the accelerator), we have to justify
169 // the fist part on the left and the accelerator on the right.
170 // TODO(jungshik): This will break in RTL UI. Currently, he/ar
171 // use the window system UI font and will not hit here.
172 std::wstring label = data->label;
173 std::wstring accel;
174 std::wstring::size_type tab_pos = label.find(L'\t');
175 if (tab_pos != std::wstring::npos) {
176 accel = label.substr(tab_pos);
177 label = label.substr(0, tab_pos);
178 }
179 DrawTextEx(hDC, const_cast<wchar_t*>(label.data()),
180 static_cast<int>(label.size()), &rect, format | DT_LEFT, NULL);
181 if (!accel.empty())
182 DrawTextEx(hDC, const_cast<wchar_t*>(accel.data()),
183 static_cast<int>(accel.size()), &rect,
184 format | DT_RIGHT, NULL);
185 SelectObject(hDC, old_font);
161 186
162 // Draw the icon after the label, otherwise it would be covered 187 // Draw the icon after the label, otherwise it would be covered
163 // by the label. 188 // by the label.
164 if (data->icon.width() != 0 && data->icon.height() != 0) { 189 if (data->icon.width() != 0 && data->icon.height() != 0) {
165 ChromeCanvas canvas(data->icon.width(), data->icon.height(), false); 190 ChromeCanvas canvas(data->icon.width(), data->icon.height(), false);
166 canvas.drawColor(SK_ColorBLACK, SkPorterDuff::kClear_Mode); 191 canvas.drawColor(SK_ColorBLACK, SkPorterDuff::kClear_Mode);
167 canvas.DrawBitmapInt(data->icon, 0, 0); 192 canvas.DrawBitmapInt(data->icon, 0, 0);
168 canvas.getTopPlatformDevice().drawToHDC(hDC, lpdis->rcItem.left + 193 canvas.getTopPlatformDevice().drawToHDC(hDC, lpdis->rcItem.left +
169 kItemLeftMargin, lpdis->rcItem.top + (lpdis->rcItem.bottom - 194 kItemLeftMargin, lpdis->rcItem.top + (lpdis->rcItem.bottom -
170 lpdis->rcItem.top - data->icon.height()) / 2, NULL); 195 lpdis->rcItem.top - data->icon.height()) / 2, NULL);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 kEmptyIcon = new SkBitmap(); 237 kEmptyIcon = new SkBitmap();
213 return *kEmptyIcon; 238 return *kEmptyIcon;
214 } 239 }
215 240
216 Menu::Menu(Delegate* delegate, AnchorPoint anchor, HWND owner) 241 Menu::Menu(Delegate* delegate, AnchorPoint anchor, HWND owner)
217 : delegate_(delegate), 242 : delegate_(delegate),
218 menu_(CreatePopupMenu()), 243 menu_(CreatePopupMenu()),
219 anchor_(anchor), 244 anchor_(anchor),
220 owner_(owner), 245 owner_(owner),
221 is_menu_visible_(false), 246 is_menu_visible_(false),
222 owner_draw_(false) { 247 owner_draw_(l10n_util::NeedOverrideDefaultUIFont(NULL, NULL)) {
223 DCHECK(delegate_); 248 DCHECK(delegate_);
224 } 249 }
225 250
226 Menu::Menu(Menu* parent) 251 Menu::Menu(Menu* parent)
227 : delegate_(parent->delegate_), 252 : delegate_(parent->delegate_),
228 menu_(CreatePopupMenu()), 253 menu_(CreatePopupMenu()),
229 anchor_(parent->anchor_), 254 anchor_(parent->anchor_),
230 owner_(parent->owner_), 255 owner_(parent->owner_),
231 is_menu_visible_(false), 256 is_menu_visible_(false),
232 owner_draw_(false) { 257 owner_draw_(parent->owner_draw_) {
233 } 258 }
234 259
235 Menu::Menu(HMENU hmenu) 260 Menu::Menu(HMENU hmenu)
236 : delegate_(NULL), 261 : delegate_(NULL),
237 menu_(hmenu), 262 menu_(hmenu),
238 anchor_(TOPLEFT), 263 anchor_(TOPLEFT),
239 owner_(NULL), 264 owner_(NULL),
240 is_menu_visible_(false), 265 is_menu_visible_(false),
241 owner_draw_(false) { 266 owner_draw_(false) {
242 DCHECK(menu_); 267 DCHECK(menu_);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } 608 }
584 609
585 void Menu::Cancel() { 610 void Menu::Cancel() {
586 DCHECK(is_menu_visible_); 611 DCHECK(is_menu_visible_);
587 EndMenu(); 612 EndMenu();
588 } 613 }
589 614
590 int Menu::ItemCount() { 615 int Menu::ItemCount() {
591 return GetMenuItemCount(menu_); 616 return GetMenuItemCount(menu_);
592 } 617 }
OLDNEW
« no previous file with comments | « chrome/views/controls/menu/chrome_menu.cc ('k') | chrome/views/controls/table/table_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698