From 1131ae27a0f38e9b406d5b9e04d58c2dac4646cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Thu, 11 Feb 2016 16:48:51 +0000 Subject: [PATCH] gtk-demo: add menu check and radio examples note that if the "menu" context has no parent then the GTK_STATE_FLAG_NORMAL menu entries are invisible against the white background. https://bugzilla.gnome.org/show_bug.cgi?id=762080 --- demos/gtk-demo/foreigndrawing.c | 61 ++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/demos/gtk-demo/foreigndrawing.c b/demos/gtk-demo/foreigndrawing.c index c3084f353a..1ece6a2f0d 100644 --- a/demos/gtk-demo/foreigndrawing.c +++ b/demos/gtk-demo/foreigndrawing.c @@ -145,30 +145,75 @@ draw_menu (GtkWidget *widget, { GtkStyleContext *menu_context; GtkStyleContext *menuitem_context; + GtkStyleContext *hovermenuitem_context; GtkStyleContext *arrowmenuitem_context; + GtkStyleContext *checkmenuitem_context; + GtkStyleContext *radiomenuitem_context; + GtkStyleContext *disablemenuitem_context; /* This information is taken from the GtkMenu docs, see "CSS nodes" */ - menu_context = get_style (NULL, "menu"); + menu_context = get_style (gtk_widget_get_style_context(widget), "menu"); gtk_render_background (menu_context, cr, x, y, width, height); gtk_render_frame (menu_context, cr, x, y, width, height); - menuitem_context = get_style (menu_context, "menuitem:hover"); - gtk_render_background (menuitem_context, cr, x, y, width, 20); - gtk_render_frame (menuitem_context, cr, x, y, width, 20); + hovermenuitem_context = get_style (menu_context, "menuitem:hover"); + gtk_render_background (hovermenuitem_context, cr, x, y, width, 20); + gtk_render_frame (hovermenuitem_context, cr, x, y, width, 20); /* arrow for left to right */ - arrowmenuitem_context = get_style (menuitem_context, "arrow:dir(ltr)"); + arrowmenuitem_context = get_style (hovermenuitem_context, "arrow:dir(ltr)"); gtk_render_arrow (arrowmenuitem_context, cr, G_PI / 2, x + width - 20, y, 20); + g_object_unref (arrowmenuitem_context); + + menuitem_context = get_style (menu_context, "menuitem"); gtk_render_background (menuitem_context, cr, x, y + 20, width, 20); gtk_render_frame (menuitem_context, cr, x, y + 20, width, 20); - g_object_unref (arrowmenuitem_context); - /* arrow for right to left */ + disablemenuitem_context = get_style (menu_context, "menuitem:disabled"); + + /* arrow for right to left, sensitive */ arrowmenuitem_context = get_style (menuitem_context, "arrow:dir(rtl)"); gtk_render_arrow (arrowmenuitem_context, cr, G_PI / 2, x, y + 20, 20); - g_object_unref (arrowmenuitem_context); + + /* arrow for right to left, insensitive */ + arrowmenuitem_context = get_style (disablemenuitem_context, "arrow:dir(rtl)"); + gtk_render_arrow (arrowmenuitem_context, cr, G_PI / 2, x + width - 20, y + 20, 20); + + gtk_render_background (menuitem_context, cr, x, y + 40, width, 20); + gtk_render_frame (menuitem_context, cr, x, y + 40, width, 20); + + /* check enabled, sensitive */ + checkmenuitem_context = get_style (menuitem_context, "check:checked"); + gtk_render_frame (checkmenuitem_context, cr, x + 2, y + 40, 16, 16); + gtk_render_check (checkmenuitem_context, cr, x + 2, y + 40, 16, 16); + g_object_unref (checkmenuitem_context); + + /* check unchecked, insensitive */ + checkmenuitem_context = get_style (disablemenuitem_context, "check"); + gtk_render_frame (checkmenuitem_context, cr, x + width - 18, y + 40, 16, 16); + gtk_render_check (checkmenuitem_context, cr, x + width - 18, y + 40, 16, 16); + + gtk_render_background (menuitem_context, cr, x, y + 60, width, 20); + gtk_render_frame (menuitem_context, cr, x, y + 60, width, 20); + + /* radio checked, sensitive */ + radiomenuitem_context = get_style (menuitem_context, "radio:checked"); + gtk_render_frame (radiomenuitem_context, cr, x + 2, y + 60, 16, 16); + gtk_render_option (radiomenuitem_context, cr, x + 2, y + 60, 16, 16); + g_object_unref (radiomenuitem_context); + + /* radio unchecked, insensitive */ + radiomenuitem_context = get_style (disablemenuitem_context, "radio"); + gtk_render_frame (radiomenuitem_context, cr, x + width - 18, y + 60, 16, 16); + gtk_render_option (radiomenuitem_context, cr, x + width - 18, y + 60, 16, 16); + + g_object_unref (disablemenuitem_context); + g_object_unref (radiomenuitem_context); + g_object_unref (checkmenuitem_context); + g_object_unref (arrowmenuitem_context); + g_object_unref (hovermenuitem_context); g_object_unref (menuitem_context); g_object_unref (menu_context); }