This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
DropdownRibbonGroup.cs
92 lines (76 loc) · 1.79 KB
/
DropdownRibbonGroup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using Gtk;
namespace Ribbons
{
public class DropdownRibbonGroup : ToggleButton
{
private RibbonGroup group;
private SyntheticWindow win;
public RibbonGroup Group
{
get { return group; }
set { group = value; }
}
public DropdownRibbonGroup ()
{
DrawBackground = true;
ImagePosition = PositionType.Top;
isSmall = false;
DisplayArrow = true;
}
protected override void BindedWidget_ButtonReleaseEvent (object sender, ButtonReleaseEventArgs evnt)
{
base.BindedWidget_ButtonReleaseEvent (sender, evnt);
if(Value)
{
int x, y;
ParentWindow.GetOrigin (out x, out y);
x += Allocation.X;
y += Allocation.Bottom;
ShowAt (x, y);
}
else
{
KillMenu (true);
}
}
private void ShowAt (int x, int y)
{
if(win != null) return;
win = new SyntheticWindow (WindowType.Popup);
win.Child = group;
win.Hidden += delegate { KillMenu (true); };
win.ShowAll ();
win.GdkWindow.Move (x, y);
win.ButtonPressEvent += delegate { KillMenu (true); };
win.AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));
Grab.Add (win);
Gdk.GrabStatus grabbed = Gdk.Pointer.Grab (win.GdkWindow, true, Gdk.EventMask.ButtonPressMask, null, null, 0);
if(grabbed != Gdk.GrabStatus.Success)
{
KillMenu (false);
return;
}
grabbed = Gdk.Keyboard.Grab (win.GdkWindow, true, 0);
if(grabbed != Gdk.GrabStatus.Success)
{
KillMenu (false);
return;
}
}
private void KillMenu (bool Ungrab)
{
if(win == null) return;
Grab.Remove (win);
if(Ungrab)
{
Gdk.Pointer.Ungrab (0);
Gdk.Keyboard.Ungrab (0);
}
win.Hide ();
group.Unparent ();
win = null;
Value = false;
}
}
}