| 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 |
#include <gtk/gtk.h> |
| 18 |
#include <gtkmm/accelgroup.h> |
| 19 |
|
| 20 |
_DEPRECATE_IFDEF_START |
| 21 |
static void SignalProxy_PopupPosition_gtk_callback(GtkMenu*, int* x, int* y, gboolean* push_in, void* data) |
| 22 |
{ |
| 23 |
auto the_slot = static_cast<Gtk::Menu::SlotPositionCalc*>(data); |
| 24 |
|
| 25 |
int temp_x = (x) ? *x : 0; |
| 26 |
int temp_y = (y) ? *y : 0; |
| 27 |
bool temp_push_in = (push_in) ? bool(*push_in) : false; |
| 28 |
|
| 29 |
try |
| 30 |
{ |
| 31 |
(*the_slot)(temp_x, temp_y, temp_push_in); |
| 32 |
} |
| 33 |
catch(...) |
| 34 |
{ |
| 35 |
Glib::exception_handlers_invoke(); |
| 36 |
} |
| 37 |
|
| 38 |
if(x) *x = temp_x; |
| 39 |
if(y) *y = temp_y; |
| 40 |
if(push_in) *push_in = temp_push_in; |
| 41 |
} |
| 42 |
|
| 43 |
static void SignalProxy_PopupPosition_gtk_callback_destroy(void* data) |
| 44 |
{ |
| 45 |
auto the_slot = static_cast<Gtk::Menu::SlotPositionCalc*>(data); |
| 46 |
delete the_slot; |
| 47 |
} |
| 48 |
_DEPRECATE_IFDEF_END |
| 49 |
|
| 50 |
namespace Gtk |
| 51 |
{ |
| 52 |
|
| 53 |
Menu::Menu(const Glib::RefPtr<Gio::MenuModel>& model) |
| 54 |
: |
| 55 |
_CONSTRUCT() |
| 56 |
{ |
| 57 |
//g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL); |
| 58 |
|
| 59 |
bind_model(model, true); |
| 60 |
} |
| 61 |
|
| 62 |
_DEPRECATE_IFDEF_START |
| 63 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 64 |
void Menu::popup(const SlotPositionCalc& position_calc_slot, guint button, guint32 activate_time, const Glib::RefPtr<Gdk::Device>& device) |
| 65 |
{ |
| 66 |
// Tell GTK+ to call the static function with the slot's address as the extra |
| 67 |
// data, so that the static function can then call the sigc::slot: |
| 68 |
if(!device) |
| 69 |
gtk_menu_popup(gobj(), nullptr, nullptr, &SignalProxy_PopupPosition_gtk_callback, const_cast<SlotPositionCalc*>(&position_calc_slot), button, activate_time); |
| 70 |
else |
| 71 |
{ |
| 72 |
auto slot_copy = new SlotPositionCalc(position_calc_slot); //Deleted in the destroy callback. |
| 73 |
|
| 74 |
gtk_menu_popup_for_device(gobj(), device->gobj(), nullptr, nullptr, &SignalProxy_PopupPosition_gtk_callback, slot_copy, &SignalProxy_PopupPosition_gtk_callback_destroy, button, activate_time); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
void Menu::popup(MenuShell& parent_menu_shell, MenuItem& parent_menu_item, const SlotPositionCalc& position_calc_slot, guint button, guint32 activate_time, const Glib::RefPtr<Gdk::Device>& device) |
| 79 |
{ |
| 80 |
// Tell GTK+ to call the static function with the slot's address as the extra |
| 81 |
// data, so that the static function can then call the sigc::slot: |
| 82 |
if(!device) |
| 83 |
gtk_menu_popup(gobj(), parent_menu_shell.Gtk::Widget::gobj(), parent_menu_item.Gtk::Widget::gobj(), &SignalProxy_PopupPosition_gtk_callback, const_cast<SlotPositionCalc*>(&position_calc_slot), button, activate_time); |
| 84 |
else |
| 85 |
{ |
| 86 |
auto slot_copy = new SlotPositionCalc(position_calc_slot); //Deleted in the destroy callback. |
| 87 |
|
| 88 |
gtk_menu_popup_for_device(gobj(), device->gobj(), parent_menu_shell.Gtk::Widget::gobj(), parent_menu_item.Gtk::Widget::gobj(), &SignalProxy_PopupPosition_gtk_callback, slot_copy, &SignalProxy_PopupPosition_gtk_callback_destroy, button, activate_time); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
void Menu::popup(guint button, guint32 activate_time, const Glib::RefPtr<Gdk::Device>& device) |
| 93 |
{ |
| 94 |
if(!device) |
| 95 |
gtk_menu_popup(gobj(), nullptr, nullptr, nullptr, nullptr, button, activate_time); |
| 96 |
else |
| 97 |
gtk_menu_popup_for_device(gobj(), device->gobj(), nullptr, nullptr, nullptr, nullptr, nullptr, button, activate_time); |
| 98 |
} |
| 99 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 100 |
_DEPRECATE_IFDEF_END |
| 101 |
|
| 102 |
void Menu::reorder_child(const MenuItem& child, int position) |
| 103 |
{ |
| 104 |
gtk_menu_reorder_child( |
| 105 |
gobj(), |
| 106 |
const_cast<GtkWidget*>(child.Gtk::Widget::gobj()), |
| 107 |
position); |
| 108 |
} |
| 109 |
|
| 110 |
void Menu::unset_accel_group() |
| 111 |
{ |
| 112 |
gtk_menu_set_accel_group(gobj(), nullptr); |
| 113 |
} |
| 114 |
|
| 115 |
_DEPRECATE_IFDEF_START |
| 116 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 117 |
void Menu::unset_title() |
| 118 |
{ |
| 119 |
gtk_menu_set_title(gobj(), nullptr); |
| 120 |
} |
| 121 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 122 |
_DEPRECATE_IFDEF_END |
| 123 |
|
| 124 |
void Menu::attach_to_widget(Widget& attach_widget) |
| 125 |
{ |
| 126 |
gtk_menu_attach_to_widget(gobj(), (attach_widget).gobj(), nullptr /* allowed by the C docs. */); |
| 127 |
} |
| 128 |
|
| 129 |
} // namespace Gtk |