OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/gtk_custom_menu.h" | 5 #include "chrome/browser/ui/gtk/gtk_custom_menu.h" |
6 | 6 |
7 #include "chrome/browser/ui/gtk/gtk_custom_menu_item.h" | 7 #include "chrome/browser/ui/gtk/gtk_custom_menu_item.h" |
8 | 8 |
9 G_DEFINE_TYPE(GtkCustomMenu, gtk_custom_menu, GTK_TYPE_MENU) | 9 G_DEFINE_TYPE(GtkCustomMenu, gtk_custom_menu, GTK_TYPE_MENU) |
10 | 10 |
11 // Stolen directly from gtkmenushell.c. I'd love to call the library version | 11 // Stolen directly from gtkmenushell.c. I'd love to call the library version |
12 // instead, but it's static and isn't exported. :( | 12 // instead, but it's static and isn't exported. :( |
13 static gint gtk_menu_shell_is_item(GtkMenuShell* menu_shell, | 13 static gint gtk_menu_shell_is_item(GtkMenuShell* menu_shell, |
14 GtkWidget* child) { | 14 GtkWidget* child) { |
15 GtkWidget *parent; | 15 GtkWidget *parent; |
16 | 16 |
17 g_return_val_if_fail(GTK_IS_MENU_SHELL(menu_shell), FALSE); | 17 g_return_val_if_fail(GTK_IS_MENU_SHELL(menu_shell), FALSE); |
18 g_return_val_if_fail(child != NULL, FALSE); | 18 g_return_val_if_fail(child != NULL, FALSE); |
19 | 19 |
20 parent = child->parent; | 20 parent = gtk_widget_get_parent(child); |
21 while (GTK_IS_MENU_SHELL(parent)) { | 21 while (GTK_IS_MENU_SHELL(parent)) { |
22 if (parent == reinterpret_cast<GtkWidget*>(menu_shell)) | 22 if (parent == reinterpret_cast<GtkWidget*>(menu_shell)) |
23 return TRUE; | 23 return TRUE; |
24 parent = GTK_MENU_SHELL(parent)->parent_menu_shell; | 24 parent = GTK_MENU_SHELL(parent)->parent_menu_shell; |
25 } | 25 } |
26 | 26 |
27 return FALSE; | 27 return FALSE; |
28 } | 28 } |
29 | 29 |
30 // Stolen directly from gtkmenushell.c. I'd love to call the library version | 30 // Stolen directly from gtkmenushell.c. I'd love to call the library version |
31 // instead, but it's static and isn't exported. :( | 31 // instead, but it's static and isn't exported. :( |
32 static GtkWidget* gtk_menu_shell_get_item(GtkMenuShell* menu_shell, | 32 static GtkWidget* gtk_menu_shell_get_item(GtkMenuShell* menu_shell, |
33 GdkEvent* event) { | 33 GdkEvent* event) { |
34 GtkWidget* menu_item = gtk_get_event_widget(event); | 34 GtkWidget* menu_item = gtk_get_event_widget(event); |
35 | 35 |
36 while (menu_item && !GTK_IS_MENU_ITEM(menu_item)) | 36 while (menu_item && !GTK_IS_MENU_ITEM(menu_item)) |
37 menu_item = menu_item->parent; | 37 menu_item = gtk_widget_get_parent(menu_item); |
38 | 38 |
39 if (menu_item && gtk_menu_shell_is_item(menu_shell, menu_item)) | 39 if (menu_item && gtk_menu_shell_is_item(menu_shell, menu_item)) |
40 return menu_item; | 40 return menu_item; |
41 else | 41 else |
42 return NULL; | 42 return NULL; |
43 } | 43 } |
44 | 44 |
45 // When processing a button event, abort processing if the cursor isn't in a | 45 // When processing a button event, abort processing if the cursor isn't in a |
46 // clickable region. | 46 // clickable region. |
47 static gboolean gtk_custom_menu_button_press(GtkWidget* widget, | 47 static gboolean gtk_custom_menu_button_press(GtkWidget* widget, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 widget_class->button_press_event = gtk_custom_menu_button_press; | 141 widget_class->button_press_event = gtk_custom_menu_button_press; |
142 widget_class->button_release_event = gtk_custom_menu_button_release; | 142 widget_class->button_release_event = gtk_custom_menu_button_release; |
143 widget_class->motion_notify_event = gtk_custom_menu_motion_notify; | 143 widget_class->motion_notify_event = gtk_custom_menu_motion_notify; |
144 | 144 |
145 menu_shell_class->move_current = gtk_custom_menu_move_current; | 145 menu_shell_class->move_current = gtk_custom_menu_move_current; |
146 } | 146 } |
147 | 147 |
148 GtkWidget* gtk_custom_menu_new() { | 148 GtkWidget* gtk_custom_menu_new() { |
149 return GTK_WIDGET(g_object_new(GTK_TYPE_CUSTOM_MENU, NULL)); | 149 return GTK_WIDGET(g_object_new(GTK_TYPE_CUSTOM_MENU, NULL)); |
150 } | 150 } |
OLD | NEW |