testmenubutton.c 1.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#include <gtk/gtk.h>
#include "prop-editor.h"

int main (int argc, char **argv)
{
	GtkWidget *window;
	GtkWidget *button;
	GtkWidget *grid;
	GtkWidget *entry;
	GtkWidget *menu_widget;
11
	GtkAccelGroup *accel_group;
12 13 14 15 16 17 18 19 20 21 22
	guint i;
	GMenu *menu;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_resize (GTK_WINDOW (window), 400, 300);

	grid = gtk_grid_new ();
	gtk_container_add (GTK_CONTAINER (window), grid);

23 24 25
	accel_group = gtk_accel_group_new ();
	gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	/* Button next to entry */
	entry = gtk_entry_new ();
	gtk_grid_attach (GTK_GRID (grid),
			 entry,
			 0, 0,
			 1, 1);
	button = gtk_menu_button_new ();
	gtk_grid_attach (GTK_GRID (grid),
			 button,
			 1, 0,
			 1, 1);

	/* Button with GtkMenu */
	menu_widget = gtk_menu_new ();
	for (i = 5; i > 0; i--) {
		GtkWidget *item;

43 44 45 46 47 48 49 50 51 52
		if (i == 3) {
			item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, accel_group);
		} else {
			char *label;

			label = g_strdup_printf ("Item _%d", i);
			item = gtk_menu_item_new_with_mnemonic (label);
			g_free (label);
		}
		gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item), TRUE);
53 54 55 56 57 58 59 60
		gtk_menu_attach (GTK_MENU (menu_widget),
				 item,
				 0, 1,
				 i - 1, i);
	}
	gtk_widget_show_all (menu_widget);

	button = gtk_menu_button_new ();
61
	gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget);
62 63 64 65 66 67 68 69 70 71
	gtk_grid_attach (GTK_GRID (grid),
			 button,
			 1, 1,
			 1, 1);
	gtk_widget_show (create_prop_editor (G_OBJECT (button), 0));

	/* Button with GMenuModel */
	menu = g_menu_new ();
	for (i = 5; i > 0; i--) {
		char *label;
72
		label = g_strdup_printf ("Item _%d", i);
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
		g_menu_insert (menu, i - 1, label, NULL);
		g_free (label);
	}
	button = gtk_menu_button_new ();
	gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu));
	gtk_grid_attach (GTK_GRID (grid),
			 button,
			 1, 2,
			 1, 1);

	gtk_widget_show_all (window);

	gtk_main ();

	return 0;
}