3
public abstract class ToolButtonWithMenu : ToggleToolButton
6
private PositionType _menu_orientation;
7
protected PositionType menu_orientation{
9
if(value == PositionType.TOP || value == PositionType.BOTTOM){
10
value = PositionType.LEFT;
13
_menu_orientation = value;
16
return _menu_orientation;
20
public ToolButtonWithMenu (Image image, string label, Menu _menu, PositionType menu_orientation = PositionType.LEFT)
22
this.menu_orientation = menu_orientation;
25
label_widget = new Label (label);
26
((Label) label_widget).use_underline = true;
28
set_tooltip_text ("Menu");
30
menu.attach_to_widget (this, null);
31
menu.deactivate.connect(() => {
35
mnemonic_activate.connect(on_mnemonic_activate);
36
menu.deactivate.connect(popdown_menu);
39
private bool on_mnemonic_activate (bool group_cycling)
41
// ToggleButton always grabs focus away from the editor,
42
// so reimplement Widget's version, which only grabs the
43
// focus if we are group cycling.
46
} else if (can_focus) {
53
protected new void popup_menu(Gdk.EventButton? ev)
59
(ev == null) ? 0 : ev.button,
60
(ev == null) ? get_current_event_time() : ev.time);
62
// Highlight the parent
63
if (menu.attach_widget != null)
64
menu.attach_widget.set_state(StateType.SELECTED);
68
protected void popdown_menu ()
72
// Unhighlight the parent
73
if (menu.attach_widget != null)
74
menu.attach_widget.set_state(Gtk.StateType.NORMAL);
77
public override void show_all(){
82
private void get_menu_position (Menu menu, out int x, out int y, out bool push_in)
84
if (menu.attach_widget == null ||
85
menu.attach_widget.get_window() == null) {
86
// Prevent null exception in weird cases
93
menu.attach_widget.get_window().get_origin (out x, out y);
94
Allocation allocation;
95
menu.attach_widget.get_allocation(out allocation);
102
menu.get_size_request(out width, out height);
104
if (y + height >= menu.attach_widget.get_screen().get_height())
107
y += allocation.height;