aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2013-04-26 08:48:46 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2013-04-26 08:48:46 -0500
commitbf9b255f484fd61cbaa91faeff254140a0ecd18c (patch)
tree46794dcb0f4f0419384df9a08538724f6218476e /ui
parentc34688f9015c5dacc81efc4f2a0df5742d9c927c (diff)
gtk: refactor menu creation
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk.c93
1 files changed, 56 insertions, 37 deletions
diff --git a/ui/gtk.c b/ui/gtk.c
index 42e3c0aad8..e12f22838e 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1126,7 +1126,8 @@ static gboolean gd_vc_in(GIOChannel *chan, GIOCondition cond, void *opaque)
return TRUE;
}
-static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSList *group)
+static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSList *group,
+ GtkWidget *view_menu)
{
const char *label;
char buffer[32];
@@ -1193,7 +1194,7 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL
g_signal_connect(vc->menu_item, "activate",
G_CALLBACK(gd_menu_switch_vc), s);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), vc->menu_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
qemu_chr_be_generic_open(vc->chr);
if (vc->chr->init) {
@@ -1268,121 +1269,139 @@ static void gd_connect_signals(GtkDisplayState *s)
G_CALLBACK(gd_focus_out_event), s);
}
-static void gd_create_menus(GtkDisplayState *s)
+static GtkWidget *gd_create_menu_machine(GtkDisplayState *s, GtkAccelGroup *accel_group)
{
- GtkStockItem item;
- GtkAccelGroup *accel_group;
- GSList *group = NULL;
+ GtkWidget *machine_menu;
GtkWidget *separator;
- int i;
+ GtkStockItem item;
- accel_group = gtk_accel_group_new();
- s->machine_menu = gtk_menu_new();
- gtk_menu_set_accel_group(GTK_MENU(s->machine_menu), accel_group);
- s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine"));
+ machine_menu = gtk_menu_new();
+ gtk_menu_set_accel_group(GTK_MENU(machine_menu), accel_group);
s->pause_item = gtk_check_menu_item_new_with_mnemonic(_("_Pause"));
- gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->pause_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->pause_item);
separator = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), separator);
+ gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), separator);
s->reset_item = gtk_image_menu_item_new_with_mnemonic(_("_Reset"));
- gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->reset_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->reset_item);
s->powerdown_item = gtk_image_menu_item_new_with_mnemonic(_("Power _Down"));
- gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->powerdown_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->powerdown_item);
separator = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), separator);
+ gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), separator);
s->quit_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
gtk_stock_lookup(GTK_STOCK_QUIT, &item);
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->quit_item),
"<QEMU>/Machine/Quit");
gtk_accel_map_add_entry("<QEMU>/Machine/Quit", item.keyval, item.modifier);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->quit_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->quit_item);
- s->view_menu = gtk_menu_new();
- gtk_menu_set_accel_group(GTK_MENU(s->view_menu), accel_group);
- s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View"));
+ return machine_menu;
+}
+
+static GtkWidget *gd_create_menu_view(GtkDisplayState *s, GtkAccelGroup *accel_group)
+{
+ GSList *group = NULL;
+ GtkWidget *view_menu;
+ GtkWidget *separator;
+ int i;
+
+ view_menu = gtk_menu_new();
+ gtk_menu_set_accel_group(GTK_MENU(view_menu), accel_group);
s->full_screen_item =
gtk_image_menu_item_new_from_stock(GTK_STOCK_FULLSCREEN, NULL);
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->full_screen_item),
"<QEMU>/View/Full Screen");
gtk_accel_map_add_entry("<QEMU>/View/Full Screen", GDK_KEY_f, GDK_CONTROL_MASK | GDK_MOD1_MASK);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->full_screen_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->full_screen_item);
separator = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
s->zoom_in_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN, NULL);
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_in_item),
"<QEMU>/View/Zoom In");
gtk_accel_map_add_entry("<QEMU>/View/Zoom In", GDK_KEY_plus, GDK_CONTROL_MASK | GDK_MOD1_MASK);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_in_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_in_item);
s->zoom_out_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT, NULL);
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_out_item),
"<QEMU>/View/Zoom Out");
gtk_accel_map_add_entry("<QEMU>/View/Zoom Out", GDK_KEY_minus, GDK_CONTROL_MASK | GDK_MOD1_MASK);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_out_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_out_item);
s->zoom_fixed_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100, NULL);
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_fixed_item),
"<QEMU>/View/Zoom Fixed");
gtk_accel_map_add_entry("<QEMU>/View/Zoom Fixed", GDK_KEY_0, GDK_CONTROL_MASK | GDK_MOD1_MASK);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_fixed_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fixed_item);
s->zoom_fit_item = gtk_check_menu_item_new_with_mnemonic(_("Zoom To _Fit"));
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_fit_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fit_item);
separator = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
s->grab_on_hover_item = gtk_check_menu_item_new_with_mnemonic(_("Grab On _Hover"));
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->grab_on_hover_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item);
s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
"<QEMU>/View/Grab Input");
gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g, GDK_CONTROL_MASK | GDK_MOD1_MASK);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->grab_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);
separator = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
s->vga_item = gtk_radio_menu_item_new_with_mnemonic(group, "_VGA");
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(s->vga_item));
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->vga_item),
"<QEMU>/View/VGA");
gtk_accel_map_add_entry("<QEMU>/View/VGA", GDK_KEY_1, GDK_CONTROL_MASK | GDK_MOD1_MASK);
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->vga_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->vga_item);
for (i = 0; i < nb_vcs; i++) {
VirtualConsole *vc = &s->vc[i];
- group = gd_vc_init(s, vc, i, group);
+ group = gd_vc_init(s, vc, i, group, view_menu);
s->nb_vcs++;
}
separator = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
s->show_tabs_item = gtk_check_menu_item_new_with_mnemonic(_("Show _Tabs"));
- gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->show_tabs_item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->show_tabs_item);
- g_object_set_data(G_OBJECT(s->window), "accel_group", accel_group);
- gtk_window_add_accel_group(GTK_WINDOW(s->window), accel_group);
- s->accel_group = accel_group;
+ return view_menu;
+}
+
+static void gd_create_menus(GtkDisplayState *s)
+{
+ GtkAccelGroup *accel_group;
+ accel_group = gtk_accel_group_new();
+ s->machine_menu = gd_create_menu_machine(s, accel_group);
+ s->view_menu = gd_create_menu_view(s, accel_group);
+
+ s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->machine_menu_item),
s->machine_menu);
gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->machine_menu_item);
+ s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->view_menu_item), s->view_menu);
gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->view_menu_item);
+
+ g_object_set_data(G_OBJECT(s->window), "accel_group", accel_group);
+ gtk_window_add_accel_group(GTK_WINDOW(s->window), accel_group);
+ s->accel_group = accel_group;
}
static const DisplayChangeListenerOps dcl_ops = {