Hooked menus up to windows on the GTK+ backend.
This commit is contained in:
parent
e18727cff6
commit
26e42bc1ba
|
@ -274,4 +274,50 @@ void menuDestroy(void)
|
|||
}
|
||||
g_array_free(menus, TRUE);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
static void appendMenuItem(GtkMenuShell *submenu, struct menuItem *item, uiWindow *w)
|
||||
{
|
||||
GtkWidget *menuitem;
|
||||
|
||||
menuitem = g_object_new(G_OBJECT_TYPE(item->baseItem), NULL);
|
||||
if (item->name != NULL)
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(menuitem), item->name);
|
||||
if (item->type != typeSeparator) {
|
||||
g_signal_connect(menuitem, "activate", G_CALLBACK(onClicked), item);
|
||||
if (item->type == typeCheckbox)
|
||||
g_object_bind_property(item->baseItem, "active",
|
||||
menuitem, "active",
|
||||
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
||||
}
|
||||
gtk_menu_shell_append(submenu, menuitem);
|
||||
g_hash_table_insert(item->uiWindows, menuitem, w);
|
||||
}
|
||||
|
||||
// TODO should this return a zero-height widget (or NULL) if there are no menus defined?
|
||||
GtkWidget *makeMenubar(uiWindow *w)
|
||||
{
|
||||
GtkWidget *menubar;
|
||||
guint i, j;
|
||||
struct menu *m;
|
||||
GtkWidget *menuitem;
|
||||
GtkWidget *submenu;
|
||||
|
||||
menusFinalized = TRUE;
|
||||
|
||||
menubar = gtk_menu_bar_new();
|
||||
|
||||
for (i = 0; i < menus->len; i++) {
|
||||
m = &g_array_index(menus, struct menu, i);
|
||||
menuitem = gtk_menu_item_new_with_label(m->name);
|
||||
submenu = gtk_menu_new();
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
|
||||
for (j = 0; j < m->items->len; j++)
|
||||
appendMenuItem(GTK_MENU_SHELL(submenu), &g_array_index(m->items, struct menuItem, j), w);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
|
||||
}
|
||||
|
||||
gtk_widget_set_hexpand(menubar, TRUE);
|
||||
gtk_widget_set_halign(menubar, GTK_ALIGN_FILL);
|
||||
return menubar;
|
||||
}
|
||||
|
|
|
@ -13,3 +13,6 @@
|
|||
|
||||
// text.c
|
||||
extern char *strdupText(const char *);
|
||||
|
||||
// menu.c
|
||||
extern GtkWidget *makeMenubar(uiWindow *);
|
||||
|
|
|
@ -131,7 +131,7 @@ static void windowSetMargined(uiWindow *ww, int margined)
|
|||
uiOSContainerUpdate(w->content);
|
||||
}
|
||||
|
||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubars)
|
||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||
{
|
||||
struct window *w;
|
||||
|
||||
|
@ -148,7 +148,8 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubars)
|
|||
// set the vbox as the GtkWindow child
|
||||
gtk_container_add(w->container, w->vboxwidget);
|
||||
|
||||
// TODO menus
|
||||
if (hasMenubar)
|
||||
gtk_container_add(w->vboxcontainer, makeMenubar(uiWindow(w)));
|
||||
|
||||
// and add the OS container
|
||||
w->content = uiNewOSContainer((uintptr_t) (w->vboxcontainer));
|
||||
|
|
Loading…
Reference in New Issue