2 // These are shamelessly stolen from Tomboy.
11 public static void GetMenuPosition (Gtk
.Menu menu
,
16 Gtk
.Requisition menu_req
= menu
.SizeRequest ();
18 menu
.AttachWidget
.GdkWindow
.GetOrigin (out x
, out y
);
20 if (y
+ menu_req
.Height
>= menu
.AttachWidget
.Screen
.Height
)
23 y
+= menu
.AttachWidget
.Allocation
.Height
;
28 static void DeactivateMenu (object sender
, EventArgs args
)
30 Gtk
.Menu menu
= (Gtk
.Menu
) sender
;
34 // Place the menu underneath an arbitrary parent widget. The
35 // parent widget must be set using menu.AttachToWidget before
37 public static void PopupMenu (Gtk
.Menu menu
, Gdk
.EventButton ev
)
39 menu
.Deactivated
+= new EventHandler (DeactivateMenu
);
42 new Gtk
.MenuPositionFunc (GetMenuPosition
),
43 (ev
== null) ? 0 : ev
.Button
,
44 (ev
== null) ? Gtk
.Global
.CurrentEventTime
: ev
.Time
);
47 public static Gdk
.Pixbuf
GetMiniIcon (string resource_name
)
49 Gdk
.Pixbuf noicon
= new Gdk
.Pixbuf (null, resource_name
);
50 return noicon
.ScaleSimple (24, 24, Gdk
.InterpType
.Nearest
);
53 public static Gtk
.Button
MakeImageButton (Gtk
.Image image
, string label
)
55 Gtk
.HBox box
= new Gtk
.HBox (false, 2);
56 box
.PackStart (image
, false, false, 0);
57 box
.PackEnd (new Gtk
.Label (label
), false, false, 0);
60 Gtk
.Button button
= new Gtk
.Button ();
62 Gtk
.Alignment align
= new Gtk
.Alignment (0.5f
, 0.5f
, 0.0f
, 0.0f
);
70 public static Gtk
.Button
MakeImageButton (string stock_id
, string label
)
72 Gtk
.Image image
= new Gtk
.Image (stock_id
, Gtk
.IconSize
.Button
);
73 return MakeImageButton (image
, label
);
77 public class GlobalKeybinder
79 Gtk
.AccelGroup accel_group
;
82 public GlobalKeybinder (Gtk
.AccelGroup accel_group
)
84 this.accel_group
= accel_group
;
86 fake_menu
= new Gtk
.Menu ();
87 fake_menu
.AccelGroup
= accel_group
;
90 public void AddAccelerator (EventHandler handler
,
92 Gdk
.ModifierType modifiers
,
95 Gtk
.MenuItem foo
= new Gtk
.MenuItem ();
96 foo
.Activated
+= handler
;
97 foo
.AddAccelerator ("activate",
104 fake_menu
.Append (foo
);