gtk: refactor menu creation
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
c34688f901
commit
bf9b255f48
93
ui/gtk.c
93
ui/gtk.c
@ -1126,7 +1126,8 @@ static gboolean gd_vc_in(GIOChannel *chan, GIOCondition cond, void *opaque)
|
|||||||
return TRUE;
|
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;
|
const char *label;
|
||||||
char buffer[32];
|
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_signal_connect(vc->menu_item, "activate",
|
||||||
G_CALLBACK(gd_menu_switch_vc), s);
|
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);
|
qemu_chr_be_generic_open(vc->chr);
|
||||||
if (vc->chr->init) {
|
if (vc->chr->init) {
|
||||||
@ -1268,121 +1269,139 @@ static void gd_connect_signals(GtkDisplayState *s)
|
|||||||
G_CALLBACK(gd_focus_out_event), 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;
|
GtkWidget *machine_menu;
|
||||||
GtkAccelGroup *accel_group;
|
|
||||||
GSList *group = NULL;
|
|
||||||
GtkWidget *separator;
|
GtkWidget *separator;
|
||||||
int i;
|
GtkStockItem item;
|
||||||
|
|
||||||
accel_group = gtk_accel_group_new();
|
machine_menu = gtk_menu_new();
|
||||||
s->machine_menu = gtk_menu_new();
|
gtk_menu_set_accel_group(GTK_MENU(machine_menu), accel_group);
|
||||||
gtk_menu_set_accel_group(GTK_MENU(s->machine_menu), accel_group);
|
|
||||||
s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine"));
|
|
||||||
|
|
||||||
s->pause_item = gtk_check_menu_item_new_with_mnemonic(_("_Pause"));
|
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();
|
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"));
|
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"));
|
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();
|
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);
|
s->quit_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
|
||||||
gtk_stock_lookup(GTK_STOCK_QUIT, &item);
|
gtk_stock_lookup(GTK_STOCK_QUIT, &item);
|
||||||
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->quit_item),
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->quit_item),
|
||||||
"<QEMU>/Machine/Quit");
|
"<QEMU>/Machine/Quit");
|
||||||
gtk_accel_map_add_entry("<QEMU>/Machine/Quit", item.keyval, item.modifier);
|
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();
|
return machine_menu;
|
||||||
gtk_menu_set_accel_group(GTK_MENU(s->view_menu), accel_group);
|
}
|
||||||
s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View"));
|
|
||||||
|
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 =
|
s->full_screen_item =
|
||||||
gtk_image_menu_item_new_from_stock(GTK_STOCK_FULLSCREEN, NULL);
|
gtk_image_menu_item_new_from_stock(GTK_STOCK_FULLSCREEN, NULL);
|
||||||
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->full_screen_item),
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->full_screen_item),
|
||||||
"<QEMU>/View/Full Screen");
|
"<QEMU>/View/Full Screen");
|
||||||
gtk_accel_map_add_entry("<QEMU>/View/Full Screen", GDK_KEY_f, GDK_CONTROL_MASK | GDK_MOD1_MASK);
|
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();
|
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);
|
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),
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_in_item),
|
||||||
"<QEMU>/View/Zoom In");
|
"<QEMU>/View/Zoom In");
|
||||||
gtk_accel_map_add_entry("<QEMU>/View/Zoom In", GDK_KEY_plus, GDK_CONTROL_MASK | GDK_MOD1_MASK);
|
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);
|
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),
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_out_item),
|
||||||
"<QEMU>/View/Zoom Out");
|
"<QEMU>/View/Zoom Out");
|
||||||
gtk_accel_map_add_entry("<QEMU>/View/Zoom Out", GDK_KEY_minus, GDK_CONTROL_MASK | GDK_MOD1_MASK);
|
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);
|
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),
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_fixed_item),
|
||||||
"<QEMU>/View/Zoom Fixed");
|
"<QEMU>/View/Zoom Fixed");
|
||||||
gtk_accel_map_add_entry("<QEMU>/View/Zoom Fixed", GDK_KEY_0, GDK_CONTROL_MASK | GDK_MOD1_MASK);
|
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"));
|
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();
|
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"));
|
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"));
|
s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
|
||||||
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
|
||||||
"<QEMU>/View/Grab Input");
|
"<QEMU>/View/Grab Input");
|
||||||
gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g, GDK_CONTROL_MASK | GDK_MOD1_MASK);
|
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();
|
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");
|
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));
|
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),
|
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->vga_item),
|
||||||
"<QEMU>/View/VGA");
|
"<QEMU>/View/VGA");
|
||||||
gtk_accel_map_add_entry("<QEMU>/View/VGA", GDK_KEY_1, GDK_CONTROL_MASK | GDK_MOD1_MASK);
|
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++) {
|
for (i = 0; i < nb_vcs; i++) {
|
||||||
VirtualConsole *vc = &s->vc[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++;
|
s->nb_vcs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
separator = gtk_separator_menu_item_new();
|
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"));
|
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);
|
return view_menu;
|
||||||
gtk_window_add_accel_group(GTK_WINDOW(s->window), accel_group);
|
}
|
||||||
s->accel_group = accel_group;
|
|
||||||
|
|
||||||
|
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),
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->machine_menu_item),
|
||||||
s->machine_menu);
|
s->machine_menu);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->machine_menu_item);
|
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_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);
|
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 = {
|
static const DisplayChangeListenerOps dcl_ops = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user