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

Side by Side Diff: chrome/browser/gtk/menu_gtk.cc

Issue 548074: GTK: respect menu model's radio button groupings.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 11 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 | « no previous file | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser/gtk/menu_gtk.h" 5 #include "chrome/browser/gtk/menu_gtk.h"
6 6
7 #include "app/gfx/gtk_util.h" 7 #include "app/gfx/gtk_util.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "app/menus/accelerator_gtk.h" 9 #include "app/menus/accelerator_gtk.h"
10 #include "app/menus/menu_model.h" 10 #include "app/menus/menu_model.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 gtk_util::SetAlwaysShowImage(menu_item); 243 gtk_util::SetAlwaysShowImage(menu_item);
244 244
245 return menu_item; 245 return menu_item;
246 } 246 }
247 247
248 void MenuGtk::BuildMenuFromModel() { 248 void MenuGtk::BuildMenuFromModel() {
249 BuildSubmenuFromModel(model_, menu_); 249 BuildSubmenuFromModel(model_, menu_);
250 } 250 }
251 251
252 void MenuGtk::BuildSubmenuFromModel(menus::MenuModel* model, GtkWidget* menu) { 252 void MenuGtk::BuildSubmenuFromModel(menus::MenuModel* model, GtkWidget* menu) {
253 GtkWidget* last_menu_item = NULL; 253 std::map<int, GtkWidget*> radio_groups;
254 GtkWidget* menu_item = NULL; 254 GtkWidget* menu_item = NULL;
255 for (int i = 0; i < model->GetItemCount(); ++i) { 255 for (int i = 0; i < model->GetItemCount(); ++i) {
256 SkBitmap icon; 256 SkBitmap icon;
257 std::string label = 257 std::string label =
258 ConvertAcceleratorsFromWindowsStyle(UTF16ToUTF8(model->GetLabelAt(i))); 258 ConvertAcceleratorsFromWindowsStyle(UTF16ToUTF8(model->GetLabelAt(i)));
259 259
260 switch (model->GetTypeAt(i)) { 260 switch (model->GetTypeAt(i)) {
261 case menus::MenuModel::TYPE_SEPARATOR: 261 case menus::MenuModel::TYPE_SEPARATOR:
262 menu_item = gtk_separator_menu_item_new(); 262 menu_item = gtk_separator_menu_item_new();
263 break; 263 break;
264 264
265 case menus::MenuModel::TYPE_CHECK: 265 case menus::MenuModel::TYPE_CHECK:
266 menu_item = gtk_check_menu_item_new_with_mnemonic(label.c_str()); 266 menu_item = gtk_check_menu_item_new_with_mnemonic(label.c_str());
267 break; 267 break;
268 268
269 case menus::MenuModel::TYPE_RADIO: 269 case menus::MenuModel::TYPE_RADIO: {
270 if (last_menu_item && GTK_IS_RADIO_MENU_ITEM(last_menu_item)) { 270 std::map<int, GtkWidget*>::iterator iter =
271 menu_item = gtk_radio_menu_item_new_with_mnemonic_from_widget( 271 radio_groups.find(model->GetGroupIdAt(i));
272 GTK_RADIO_MENU_ITEM(last_menu_item), label.c_str()); 272
273 } else { 273 if (iter == radio_groups.end()) {
274 menu_item = gtk_radio_menu_item_new_with_mnemonic( 274 menu_item = gtk_radio_menu_item_new_with_mnemonic(
275 NULL, label.c_str()); 275 NULL, label.c_str());
276 radio_groups[model->GetGroupIdAt(i)] = menu_item;
277 } else {
278 menu_item = gtk_radio_menu_item_new_with_mnemonic_from_widget(
279 GTK_RADIO_MENU_ITEM(iter->second), label.c_str());
276 } 280 }
277 break; 281 break;
278 282 }
279 case menus::MenuModel::TYPE_SUBMENU: 283 case menus::MenuModel::TYPE_SUBMENU:
280 case menus::MenuModel::TYPE_COMMAND: 284 case menus::MenuModel::TYPE_COMMAND:
281 if (model->GetIconAt(i, &icon)) 285 if (model->GetIconAt(i, &icon))
282 menu_item = BuildMenuItemWithImage(label, icon); 286 menu_item = BuildMenuItemWithImage(label, icon);
283 else 287 else
284 menu_item = gtk_menu_item_new_with_mnemonic(label.c_str()); 288 menu_item = gtk_menu_item_new_with_mnemonic(label.c_str());
285 break; 289 break;
286 290
287 default: 291 default:
288 NOTREACHED(); 292 NOTREACHED();
(...skipping 12 matching lines...) Expand all
301 dummy_accel_group_, 305 dummy_accel_group_,
302 accelerator.GetGdkKeyCode(), 306 accelerator.GetGdkKeyCode(),
303 accelerator.gdk_modifier_type(), 307 accelerator.gdk_modifier_type(),
304 GTK_ACCEL_VISIBLE); 308 GTK_ACCEL_VISIBLE);
305 } 309 }
306 310
307 g_object_set_data(G_OBJECT(menu_item), "model", 311 g_object_set_data(G_OBJECT(menu_item), "model",
308 reinterpret_cast<void*>(model)); 312 reinterpret_cast<void*>(model));
309 AppendMenuItemToMenu(i, menu_item, menu); 313 AppendMenuItemToMenu(i, menu_item, menu);
310 314
311 last_menu_item = menu_item;
312 menu_item = NULL; 315 menu_item = NULL;
313 } 316 }
314 } 317 }
315 318
316 // static 319 // static
317 void MenuGtk::OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu) { 320 void MenuGtk::OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu) {
318 if (block_activation_) 321 if (block_activation_)
319 return; 322 return;
320 323
321 // We receive activation messages when highlighting a menu that has a 324 // We receive activation messages when highlighting a menu that has a
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 if (GTK_IS_MENU_ITEM(widget)) { 499 if (GTK_IS_MENU_ITEM(widget)) {
497 gtk_widget_set_sensitive(widget, menu->IsCommandEnabled(model, id)); 500 gtk_widget_set_sensitive(widget, menu->IsCommandEnabled(model, id));
498 501
499 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); 502 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget));
500 if (submenu) { 503 if (submenu) {
501 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, 504 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo,
502 userdata); 505 userdata);
503 } 506 }
504 } 507 }
505 } 508 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698