| 1 |
/* Copyright (C) 1998-2002 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
_DEFS(gtkmm,gtk) |
| 18 |
_PINCLUDE(gtkmm/private/menushell_p.h) |
| 19 |
|
| 20 |
#include <gdkmm/window.h> |
| 21 |
#include <gtkmm/menushell.h> |
| 22 |
#include <gtkmm/menuitem.h> |
| 23 |
|
| 24 |
namespace Gtk |
| 25 |
{ |
| 26 |
|
| 27 |
class GTKMM_API AccelGroup; |
| 28 |
|
| 29 |
/** @defgroup Menus Menu classes |
| 30 |
*/ |
| 31 |
|
| 32 |
/** A drop-down menu consisting of Gtk::MenuItem objects which can be navigated and activated by the user to perform application functions. |
| 33 |
* Menus are normally placed inside a Gtk::MenuBar or another MenuItem as a sub menu. |
| 34 |
* A Menu can also be popped up, for instance as a right-click context menu, by calling the popup() method. |
| 35 |
* |
| 36 |
* @ingroup Widgets |
| 37 |
* @ingroup Menus |
| 38 |
*/ |
| 39 |
class GTKMM_API Menu : public MenuShell |
| 40 |
{ |
| 41 |
_CLASS_GTKOBJECT(Menu,GtkMenu,GTK_MENU,Gtk::MenuShell,GtkMenuShell,,,GTKMM_API) |
| 42 |
public: |
| 43 |
_CTOR_DEFAULT |
| 44 |
|
| 45 |
//This is custom-implemented because the gtk_menu_new_from_model() does more |
| 46 |
//than just call g_object_new. See https://bugzilla.gnome.org/show_bug.cgi?id=704671 |
| 47 |
/** Creates a new Menu and populates it with menu items |
| 48 |
* and submenus according to the @a model. |
| 49 |
* |
| 50 |
* The created menu items are connected to actions found in the |
| 51 |
* ApplicationWindow to which the menu belongs - typically |
| 52 |
* by means of being attached to a widget (see attach_to_widget()) |
| 53 |
* that is contained within the ApplicationWindow's widget hierarchy. |
| 54 |
* |
| 55 |
* @param model |
| 56 |
* |
| 57 |
* @newin{3,10} |
| 58 |
*/ |
| 59 |
explicit Menu(const Glib::RefPtr<Gio::MenuModel>& model); |
| 60 |
_IGNORE(gtk_menu_new_from_model) |
| 61 |
|
| 62 |
|
| 63 |
/* append, prepend, and insert are defined in MenuShell */ |
| 64 |
|
| 65 |
_DEPRECATE_IFDEF_START |
| 66 |
/** For instance, |
| 67 |
* void on_popup_menu_position(int& x, int& y, bool& push_in); |
| 68 |
* |
| 69 |
* @deprecated |
| 70 |
*/ |
| 71 |
typedef sigc::slot<void, int&, int&, bool&> SlotPositionCalc; |
| 72 |
|
| 73 |
/** @deprecated Use popup_at_widget(), popup_at_pointer() or popup_at_rect() instead. |
| 74 |
*/ |
| 75 |
void popup(MenuShell& parent_menu_shell, MenuItem& parent_menu_item, const SlotPositionCalc& slot, guint button, guint32 activate_time, const Glib::RefPtr<Gdk::Device>& device = Glib::RefPtr<Gdk::Device>()); |
| 76 |
_IGNORE(gtk_menu_popup, gtk_menu_popup_for_device) |
| 77 |
|
| 78 |
/** Displays a menu and makes it available for selection. Applications can use |
| 79 |
* this function to display context-sensitive menus. |
| 80 |
* |
| 81 |
* The @a button parameter should be the mouse button pressed to initiate |
| 82 |
* the menu popup. If the menu popup was initiated by something other than |
| 83 |
* a mouse button press, such as a mouse button release or a keypress, |
| 84 |
* @a button should be 0. |
| 85 |
* |
| 86 |
* The @a activate_time parameter should be the time stamp of the event that |
| 87 |
* initiated the popup. If such an event is not available, use |
| 88 |
* gtk_get_current_event_time() instead. |
| 89 |
* @param position_calc_slot A user supplied function used to position the menu, or <tt>0</tt>. |
| 90 |
* @param button The mouse button which was pressed to initiate the event. |
| 91 |
* @param activate_time The time at which the activation event occurred. |
| 92 |
* @param device A Gdk::Device. |
| 93 |
* @deprecated Use popup_at_widget(), popup_at_pointer() or popup_at_rect() instead. |
| 94 |
*/ |
| 95 |
void popup(const SlotPositionCalc& position_calc_slot, guint button, guint32 activate_time, const Glib::RefPtr<Gdk::Device>& device = Glib::RefPtr<Gdk::Device>()); |
| 96 |
|
| 97 |
/** Displays a menu and makes it available for selection. |
| 98 |
* Applications can use this function to display context-sensitive menus, at the current pointer position. |
| 99 |
* @param button The button which was pressed to initiate the event. |
| 100 |
* @param activate_time The time at which the activation event occurred. |
| 101 |
* @param device A Gdk::Device. |
| 102 |
* @deprecated Use popup_at_widget(), popup_at_pointer() or popup_at_rect() instead. |
| 103 |
*/ |
| 104 |
void popup(guint button, guint32 activate_time, const Glib::RefPtr<Gdk::Device>& device = Glib::RefPtr<Gdk::Device>()); |
| 105 |
_DEPRECATE_IFDEF_END |
| 106 |
|
| 107 |
_WRAP_METHOD(void popup_at_rect(const Glib::RefPtr<Gdk::Window>& rect_window, const Gdk::Rectangle& rect, Gdk::Gravity rect_anchor, Gdk::Gravity menu_anchor, const GdkEvent* trigger_event), gtk_menu_popup_at_rect) |
| 108 |
_WRAP_METHOD(void popup_at_widget(Widget* widget, Gdk::Gravity widget_anchor, Gdk::Gravity menu_anchor, const GdkEvent* trigger_event), gtk_menu_popup_at_widget) |
| 109 |
_WRAP_METHOD(void popup_at_pointer(const GdkEvent* trigger_event), gtk_menu_popup_at_pointer) |
| 110 |
|
| 111 |
_WRAP_METHOD(void reposition(), gtk_menu_reposition) |
| 112 |
|
| 113 |
_WRAP_METHOD(void popdown(), gtk_menu_popdown) |
| 114 |
|
| 115 |
_WRAP_METHOD(MenuItem* get_active(),gtk_menu_get_active) |
| 116 |
_WRAP_METHOD(const MenuItem* get_active() const, gtk_menu_get_active, constversion) |
| 117 |
_WRAP_METHOD(void set_active(guint index),gtk_menu_set_active) |
| 118 |
|
| 119 |
_WRAP_METHOD(void set_accel_group(const Glib::RefPtr<AccelGroup>& accel_group), gtk_menu_set_accel_group) |
| 120 |
void unset_accel_group(); |
| 121 |
_WRAP_METHOD(Glib::RefPtr<AccelGroup> get_accel_group(), gtk_menu_get_accel_group, refreturn) |
| 122 |
_WRAP_METHOD(Glib::RefPtr<const AccelGroup> get_accel_group() const, gtk_menu_get_accel_group, refreturn, constversion) |
| 123 |
|
| 124 |
_WRAP_METHOD(void set_accel_path(const Glib::ustring& accel_path), gtk_menu_set_accel_path) |
| 125 |
_WRAP_METHOD(Glib::ustring get_accel_path() const, gtk_menu_get_accel_path) |
| 126 |
|
| 127 |
_WRAP_METHOD(void detach(),gtk_menu_detach) |
| 128 |
_WRAP_METHOD(Widget* get_attach_widget(), gtk_menu_get_attach_widget) |
| 129 |
_WRAP_METHOD(const Widget* get_attach_widget() const, gtk_menu_get_attach_widget, constversion) |
| 130 |
|
| 131 |
_WRAP_METHOD(void set_tearoff_state(bool torn_off = true), gtk_menu_set_tearoff_state, deprecated "No replacement available.") |
| 132 |
_WRAP_METHOD(bool get_tearoff_state() const, gtk_menu_get_tearoff_state, deprecated "No replacement available.") |
| 133 |
|
| 134 |
_WRAP_METHOD(void set_title(const Glib::ustring& title), gtk_menu_set_title, deprecated "No replacement available.") |
| 135 |
_DEPRECATE_IFDEF_START |
| 136 |
/** @deprecated No replacement available. |
| 137 |
*/ |
| 138 |
void unset_title(); |
| 139 |
_DEPRECATE_IFDEF_END |
| 140 |
_WRAP_METHOD(Glib::ustring get_title() const, gtk_menu_get_title, deprecated "No replacement available.") |
| 141 |
_WRAP_METHOD(void set_screen(const Glib::RefPtr<Gdk::Screen>& screen), gtk_menu_set_screen) |
| 142 |
|
| 143 |
_WRAP_METHOD(void attach(Gtk::Widget& child, guint left_attach, guint right_attach, guint top_attach, guint bottom_attach), gtk_menu_attach) |
| 144 |
|
| 145 |
_WRAP_METHOD(void set_monitor(int monitor_num), gtk_menu_set_monitor) |
| 146 |
_WRAP_METHOD(int get_monitor() const, gtk_menu_get_monitor) |
| 147 |
//TODO: Wrap or ignore gtk_menu_place_on_monitor(). It's not documented. Does it mean it's private? |
| 148 |
|
| 149 |
void reorder_child(const MenuItem& child, int position); |
| 150 |
_IGNORE(gtk_menu_reorder_child) |
| 151 |
|
| 152 |
_WRAP_METHOD(void set_reserve_toggle_size(bool reserve_toggle_size = true), gtk_menu_set_reserve_toggle_size) |
| 153 |
_WRAP_METHOD(bool get_reserve_toggle_size() const, gtk_menu_get_reserve_toggle_size) |
| 154 |
|
| 155 |
//TODO: What does "attach" actually mean here? murrayc |
| 156 |
// Part answer: It has become more important now that it is mentioned in the (apparently newer) gtk_menu_new_from_model() documentation. |
| 157 |
/** Attaches the menu to the widget. |
| 158 |
* |
| 159 |
* @param attach_widget The Widget that the menu will be attached to. |
| 160 |
* |
| 161 |
* @newin{2,10} |
| 162 |
*/ |
| 163 |
void attach_to_widget(Widget& attach_widget); |
| 164 |
|
| 165 |
_IGNORE_SIGNAL("move_scroll")dnl// action signal |
| 166 |
// no_default_handler because the wrapped C signal has no default handler. |
| 167 |
#m4 _CONVERSION(`gpointer',`const Gdk::Rectangle*',`&Glib::wrap((GdkRectangle*)$3)') |
| 168 |
_WRAP_SIGNAL(void popped_up(const Gdk::Rectangle* flipped_rect, const Gdk::Rectangle* final_rect, bool flipped_x, bool flipped_y), "popped-up", no_default_handler) |
| 169 |
|
| 170 |
_WRAP_PROPERTY("active", int) |
| 171 |
_WRAP_PROPERTY("accel-group", Glib::RefPtr<AccelGroup>) |
| 172 |
_WRAP_PROPERTY("accel-path", Glib::ustring) |
| 173 |
_WRAP_PROPERTY("attach-widget", Widget*) |
| 174 |
_WRAP_PROPERTY("tearoff-title", Glib::ustring, deprecated "No replacement available.") |
| 175 |
_WRAP_PROPERTY("tearoff-state", bool, deprecated "No replacement available.") |
| 176 |
_WRAP_PROPERTY("monitor", int) |
| 177 |
_WRAP_PROPERTY("reserve-toggle-size", bool) |
| 178 |
_WRAP_PROPERTY("anchor-hints", Gdk::AnchorHints) |
| 179 |
_WRAP_PROPERTY("rect-anchor-dx", int) |
| 180 |
_WRAP_PROPERTY("rect-anchor-dy", int) |
| 181 |
_WRAP_PROPERTY("menu-type-hint", Gdk::WindowTypeHint) |
| 182 |
|
| 183 |
protected: |
| 184 |
|
| 185 |
//TODO: Remove this if it has never been used, at the next ABI break? |
| 186 |
//We can not wrap this as a slot because there is no data parameter, and no destroy callback to destroy that data. |
| 187 |
typedef void (*GtkMenuDetachFunc) (GtkWidget *attach_widget, GtkMenu *menu); |
| 188 |
_WRAP_METHOD(void attach_to_widget(Widget& attach_widget, GtkMenuDetachFunc detacher), gtk_menu_attach_to_widget) |
| 189 |
|
| 190 |
}; |
| 191 |
|
| 192 |
} // namespace Gtk |