1 module gtk.PopupMenu;
2 
3 import gio.Application : GioApplication = Application;
4 import gtk.Application;
5 import gtk.ApplicationWindow;
6 import gtk.EventBox;
7 import gtk.Menu;
8 import gtk.Label;
9 import gtk.ImageMenuItem;
10 import gtk.Widget;
11 import gtk.AccelGroup;
12 import gdk.Event;
13 
14 class PopupMenuDemo : ApplicationWindow
15 {
16 	Menu menu;
17 
18 	this(Application application)
19 	{
20 		super(application);
21 		setTitle("GtkD: Popup Menu");
22 		setDefaultSize(200, 200);
23 
24 		auto eventBox = new EventBox();
25 		eventBox.add( new Label("Right click") );
26 		eventBox.addOnButtonPress(&onButtonPress);
27 		add(eventBox);
28 
29 		menu = new Menu();
30 		menu.append( new ImageMenuItem(StockID.CUT, cast(AccelGroup)null) );
31 		menu.append( new ImageMenuItem(StockID.COPY, cast(AccelGroup)null) );
32 		menu.append( new ImageMenuItem(StockID.PASTE, cast(AccelGroup)null) );
33 		menu.append( new ImageMenuItem(StockID.DELETE, cast(AccelGroup)null) );
34 		menu.attachToWidget(eventBox, null);
35 
36 		showAll();
37 	}
38 
39 	public bool onButtonPress(Event event, Widget widget)
40 	{
41 		if ( event.type == EventType.BUTTON_PRESS )
42 		{
43 			GdkEventButton* buttonEvent = event.button;
44 
45 			if ( buttonEvent.button == 3)
46 			{
47 				menu.showAll();
48 				menu.popup(buttonEvent.button, buttonEvent.time);
49 
50 				return true;
51 			}
52 		}
53 		return false;
54 	}
55 }
56 
57 int main(string[] args)
58 {
59 	auto application = new Application("org.gtkd.demo.popupmenu", GApplicationFlags.FLAGS_NONE);
60 	application.addOnActivate(delegate void(GioApplication app) { new PopupMenuDemo(application); });
61 	return application.run(args);
62 }