/* Copyright (C) 1998-2002 The gtkmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see . */ #include #include #include #include #include #include #include #include #include // gtk_menu_item_(de)select are just a wrapper for gtk_item_(de)select // and defined in Gtk_Item, so they do not be redefined here namespace Gtk { MenuItem::MenuItem(Widget& widget) : _CONSTRUCT() { add(widget); } MenuItem::MenuItem(const Glib::ustring& label, bool mnemonic) : _CONSTRUCT() { add_accel_label(label, mnemonic); /* Left-aligned label */ } void MenuItem::add_accel_label(const Glib::ustring& label, bool mnemonic) { set_label(label); set_use_underline(mnemonic); } void MenuItem::set_accel_key(const AccelKey& accel_key) { accel_key_ = accel_key; } bool MenuItem::has_submenu() const { return get_submenu() != nullptr; } void MenuItem::accelerate(Window& window) { if(!accel_key_.is_null()) { _DEPRECATE_IFDEF_START auto accel_group = window.get_accel_group(); #else // Gtk::Window::get_accel_group() does not exist if gtkmm is built // without deprecated API. Glib::RefPtr accel_group; auto accel_groups = window.get_accel_groups(); if (accel_groups.empty()) { // Create an AccelGroup for window, if there is none. accel_group = AccelGroup::create(); window.add_accel_group(accel_group); } else accel_group = accel_groups[0]; _DEPRECATE_IFDEF_END if(accel_key_.get_path().empty()) { add_accelerator("activate", accel_group, accel_key_.get_key(), accel_key_.get_mod(), ACCEL_VISIBLE); } else { AccelMap::add_entry(accel_key_.get_path().raw(), accel_key_.get_key(), accel_key_.get_mod()); Bin::set_accel_path(accel_key_.get_path(), accel_group); } } if(has_submenu()) get_submenu()->accelerate(window); } void MenuItem::unset_accel_path() { gtk_menu_item_set_accel_path(gobj(), nullptr); } void MenuItem::unset_submenu() { gtk_menu_item_set_submenu(gobj(), nullptr); } } // namespace Gtk