Fixed #374055:Only the first "tag" is detected in digikam.
[beagle.git] / Util / GtkUtils.cs
blob5e51728c0e3847b9a9a023d987d040cdd26dc366
1 //
2 // These are shamelessly stolen from Tomboy.
3 //
5 using System;
7 namespace Beagle.Util
9 public class GuiUtils
11 public static void GetMenuPosition (Gtk.Menu menu,
12 out int x,
13 out int y,
14 out bool push_in)
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)
21 y -= menu_req.Height;
22 else
23 y += menu.AttachWidget.Allocation.Height;
25 push_in = true;
28 static void DeactivateMenu (object sender, EventArgs args)
30 Gtk.Menu menu = (Gtk.Menu) sender;
31 menu.Popdown ();
34 // Place the menu underneath an arbitrary parent widget. The
35 // parent widget must be set using menu.AttachToWidget before
36 // calling this
37 public static void PopupMenu (Gtk.Menu menu, Gdk.EventButton ev)
39 menu.Deactivated += new EventHandler (DeactivateMenu);
40 menu.Popup (null,
41 null,
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);
58 box.ShowAll ();
60 Gtk.Button button = new Gtk.Button ();
62 Gtk.Alignment align = new Gtk.Alignment (0.5f, 0.5f, 0.0f, 0.0f);
63 align.Add (box);
64 align.Show ();
66 button.Add (align);
67 return button;
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;
80 Gtk.Menu fake_menu;
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,
91 uint key,
92 Gdk.ModifierType modifiers,
93 Gtk.AccelFlags flags)
95 Gtk.MenuItem foo = new Gtk.MenuItem ();
96 foo.Activated += handler;
97 foo.AddAccelerator ("activate",
98 accel_group,
99 key,
100 modifiers,
101 flags);
102 foo.Show ();
104 fake_menu.Append (foo);