| 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 |
|
| 19 |
|
| 20 |
namespace Gtk |
| 21 |
{ |
| 22 |
|
| 23 |
// All ctors are manually implemented just to initialize accel_window_. |
| 24 |
|
| 25 |
MenuShell::MenuShell() |
| 26 |
: |
| 27 |
_CONSTRUCT_SPECIFIC(Gtk::Container, MenuShell), |
| 28 |
accel_window_ (nullptr) |
| 29 |
{} |
| 30 |
|
| 31 |
MenuShell::MenuShell(const Glib::ConstructParams& construct_params) |
| 32 |
: |
| 33 |
Glib::ObjectBase(nullptr), |
| 34 |
Gtk::Container (construct_params), |
| 35 |
accel_window_ (nullptr) |
| 36 |
{} |
| 37 |
|
| 38 |
MenuShell::MenuShell(GtkMenuShell* castitem) |
| 39 |
: |
| 40 |
Gtk::Container((GtkContainer*) castitem), |
| 41 |
accel_window_ (nullptr) |
| 42 |
{} |
| 43 |
|
| 44 |
// TODO: Why do we need a custom dtor? |
| 45 |
MenuShell::~MenuShell() noexcept |
| 46 |
{} |
| 47 |
|
| 48 |
void MenuShell::accelerate(Window& window) |
| 49 |
{ |
| 50 |
// accel_window_ is used by menuitems that are added to the menushell |
| 51 |
// after it has been accelerated. |
| 52 |
accel_window_ = &window; |
| 53 |
|
| 54 |
for(auto widget : get_children()) |
| 55 |
{ |
| 56 |
auto menuitem = dynamic_cast<MenuItem*>(widget); |
| 57 |
if (menuitem) |
| 58 |
{ |
| 59 |
menuitem->accelerate(window); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
void MenuShell::accelerate(Widget& parent) |
| 65 |
{ |
| 66 |
Gtk::Window* toplevel_window |
| 67 |
= dynamic_cast<Gtk::Window*>(parent.get_toplevel()); |
| 68 |
if(toplevel_window) |
| 69 |
accelerate(*toplevel_window); |
| 70 |
} |
| 71 |
|
| 72 |
void MenuShell_Class::insert_vfunc_callback(GtkMenuShell* self, GtkWidget* child, int position) |
| 73 |
{ |
| 74 |
try |
| 75 |
{ |
| 76 |
const auto obj = dynamic_cast<MenuShell*>( |
| 77 |
Glib::ObjectBase::_get_current_wrapper((GObject*) self)); |
| 78 |
|
| 79 |
// If MenuShell is accelerated initialize accelerators of new MenuItem. |
| 80 |
if(obj && obj->accel_window_ && GTK_IS_MENU_ITEM(child)) |
| 81 |
{ |
| 82 |
Glib::wrap((GtkMenuItem*) child)->accelerate(*obj->accel_window_); |
| 83 |
} |
| 84 |
} |
| 85 |
catch(...) |
| 86 |
{ |
| 87 |
Glib::exception_handlers_invoke(); |
| 88 |
} |
| 89 |
|
| 90 |
const auto base = static_cast<GtkMenuShellClass*>( |
| 91 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self))); |
| 92 |
|
| 93 |
if(base && base->insert) |
| 94 |
(*base->insert)(self, child, position); |
| 95 |
} |
| 96 |
|
| 97 |
} // namespace Gtk |