1 module gtk.PopupMenu; 2 3 import gio.Menu; 4 import gio.MenuItem; 5 import gtk.Application; 6 import gtk.ApplicationWindow; 7 import gtk.GestureClick; 8 import gtk.Label; 9 import gtk.PopoverMenu; 10 import std.conv; 11 12 class PopupMenuDemo : ApplicationWindow 13 { 14 Menu menu; 15 PopoverMenu popupMenu; 16 GestureClick gesture; 17 18 this(Application application) 19 { 20 super(application); 21 setTitle("GtkD: Popup Menu"); 22 setDefaultSize(200, 200); 23 24 setChild( new Label("Right click") ); 25 26 gesture = new GestureClick(); 27 gesture.setButton(3); 28 gesture.addOnPressed(&onButtonPress); 29 addController(gesture); 30 31 menu = new Menu(); 32 menu.append("Cut", null); 33 menu.append("Copy", null); 34 menu.append("Paste", null); 35 menu.append("Delete", null); 36 37 popupMenu = new PopoverMenu(menu); 38 popupMenu.setParent(this); 39 popupMenu.setHasArrow(false); 40 41 show(); 42 } 43 44 public void onButtonPress(int nPress, double x, double y, GestureClick _) 45 { 46 GdkRectangle pos = GdkRectangle(to!int(x), to!int(y), 1, 1); 47 48 popupMenu.setPointingTo(&pos); 49 popupMenu.popup(); 50 } 51 } 52 53 int main(string[] args) 54 { 55 auto application = new Application("org.gtkd.demo.popupmenu", GApplicationFlags.FLAGS_NONE); 56 application.addOnActivate(delegate void(_) { new PopupMenuDemo(application); }); 57 return application.run(args); 58 }