1 module gtk.PopupMenu;
2 
3 import gtk.Main;
4 import gtk.EventBox;
5 import gtk.MainWindow;
6 import gtk.Menu;
7 import gtk.Label;
8 import gtk.ImageMenuItem;
9 import gtk.Widget;
10 import gtk.AccelGroup;
11 
12 class ExampleWindow : MainWindow
13 {
14 	Menu menu;
15 
16 	this()
17 	{
18 		super("GtkD: Popup Menu");
19 		setDefaultSize(200, 200);
20 
21 		auto eventBox = new EventBox();
22 		eventBox.add( new Label("Right click") );
23 		eventBox.addOnButtonPress(&onButtonPress);
24 		add(eventBox);
25 
26 		menu = new Menu();
27 		menu.append( new ImageMenuItem(StockID.CUT, cast(AccelGroup)null) );
28 		menu.append( new ImageMenuItem(StockID.COPY, cast(AccelGroup)null) );
29 		menu.append( new ImageMenuItem(StockID.PASTE, cast(AccelGroup)null) );
30 		menu.append( new ImageMenuItem(StockID.DELETE, cast(AccelGroup)null) );
31 		menu.attachToWidget(eventBox, null);
32 
33 		showAll();
34 	}
35 
36 	public bool onButtonPress(GdkEventButton* event, Widget widget)
37 	{
38 		if(event.type == GdkEventType.BUTTON_PRESS && event.button == 3)
39 		{
40 			menu.showAll();
41 			menu.popup(event.button, event.time);
42 
43 			return true;
44 		}
45 
46 		return false;
47 	}
48 }
49 
50 void main(string[] arg)
51 {
52 	Main.init(arg);
53 
54 	new ExampleWindow();
55 
56 	Main.run();
57 }